某人发展了数个客户,而他发展的数个客户又每一个又发展了数个客户,一直这样的发展下去,求这个人的总共客户数是多少以及他下面的每一个客户所拥有的客户总数!还有数据库应该怎么样设计呢?如果只求他直接发展的客户数我知道在数据库中设计一介绍人字段,然后:
select Count(*) from 表 where 介绍人=
恳请各位大侠指教,百思不得其解。多谢了
select Count(*) from 表 where 介绍人=
恳请各位大侠指教,百思不得其解。多谢了
晕死,真是这样啊
请给出数据库和c#代码好吗?
表结构:父ID 子ID 拥有客户数
我的表结构:父ID 层数 子ID数量 子ID
有空交流下
我的QQ是156840268
有哪位能够给出完整的c#代码吗?
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
string connString = "provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(".")+"\\hualong.mdb"+";User ID=admin;Jet OleDb:Database Password=mywin"; string selString1 = "select * from clientele where parent_id='华龙'";
OleDbConnection conn = new OleDbConnection(connString);
OleDbCommand comm = new OleDbCommand(selString,conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(selString1,conn);
dt = new DataTable();
adapter.Fill(dt);
Label2.Text = ShowAllClient("华龙");
}
}
private string ShowAllClient(string str)
{
DataRow[] drClass = dt.Select(string.Format("parent_id='{0}'",str));
int count = drClass.Length;
if(count>0)
{
foreach( DataRow dr in drClass)
{
count = count+1;
string newStr = dr["this_id"].ToString();
ShowAllClient(newStr);
}
}
string myCount = count.ToString();
return myCount;
}天啊,怎么运行不对啊?
数字不是多了就是小了啊
请高手看下代码是怎么回事啊
{
DataRow[] drClass = dt.Select(string.Format("parent_id='{0}'",str));
if(drClass.Length>0)
{
foreach( DataRow dr in drClass)
{
string newStr = dr["this_id"].ToString();
ShowAllClient(newStr);
count = count+1;
}
}
}
把count 设置为静态成员变量,把ShowAllClient设为无返回值方法,把
Label2.Text = ShowAllClient("华龙");改成
ShowAllClient("华龙");
Label2.Text =count ;(试试看,我也不知道对不对,请各位高手多多指教!!)
(第一次回贴哦!!)
{
DataRow[] drClass = dt.Select(string.Format("parent_id='{0}'",str));
int count = drClass.Length;
if(count>0)
{
foreach( DataRow dr in drClass)
{
string newStr = dr["this_id"].ToString();
count+=ShowAllClient(newStr);
}
}
return count;
}
我按照你的改了,怎么得到的数字越来越少啊?
private int ShowAllClient(string str)
{
DataRow[] drClass = dt.Select(string.Format("parent_id='{0}'",str));
int count = drClass.Length;
if(count>0)
{
foreach( DataRow dr in drClass)
{
string newStr = dr["this_id"].ToString();
count += ShowAllClient(newStr);
}
}
return count;
}
是不是int count = drClass.Length;这里的问题啊
而快乐的我试了,结果也是错误的
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
private DataTable dt;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
string connString = "provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(".")+"\\hualong.mdb"+";User ID=admin;Jet OleDb:Database Password=mywin";
string selString = "select Count(*) from clientele where parent_id='华龙'";
string selString1 = "select * from clientele where parent_id='华龙'";
OleDbConnection conn = new OleDbConnection(connString);
OleDbCommand comm = new OleDbCommand(selString,conn);
conn.Open();
Label1.Text = ((int)comm.ExecuteScalar()).ToString();
conn.Close();
OleDbDataAdapter adapter = new OleDbDataAdapter(selString1,conn);
dt = new DataTable();
adapter.Fill(dt);
Label2.Text = ShowAllClient("华龙").ToString();
}
}
private int ShowAllClient(string str)
{
DataRow[] drClass = dt.Select(string.Format("parent_id='{0}'",str));
int count = drClass.Length;
if(count>0)
{
foreach( DataRow dr in drClass)
{
string newStr = dr["this_id"].ToString();
count += ShowAllClient(newStr);
}
}
return count;
}