【发布时间】:2012-01-03 21:47:59
【问题描述】:
我想得到一个值列表,得到一个值后,我传递该值并调用相同的方法。
如果结构是这样的
60
|
61
|
63
|
64
代码运行良好,并在我通过 60 时返回所有值。
但是当结构是这样的
60
| |
61 63
|
62
所以这里 61 和 63 的父 id 是 60。
那么第一次执行后传入的Org id是63,因为61和63是同时读取的,63是最后读取的orgid,所以将63传给下一个循环,返回0,循环结束。因此没有使用 orgid 61 执行任何操作。因此错过了 62。我在这里犯了什么错误。当读取器在同一查询中读取 2 个值时,将传递读取的第二个值。我想传递查询中读取的所有值。
private DataSet BindGridView(int id, List<int> userids)
{
string GetOrgIDs = "select OrganisationID from tbl_organisation where ParentID =@ParentID";
MySqlParameter[] paramet = new MySqlParameter[1];
paramet[0] = new MySqlParameter("@ParentID", MySqlDbType.Int32);
paramet[0].Value = id;
int Orgid = 0;
MySqlDataReader reader = server.ExecuteReader(CommandType.Text, GetOrgIDs, paramet);
while (reader.Read())
{
Orgid = Convert.ToInt32(reader["OrganisationID"]);
userids.Add(Orgid);
}
reader.Close();
if (Orgid != 0)
{
BindGridView(Orgid, userids);
}
}
我从页面加载中调用方法
List<int> OrgIDs = new List<int>();
OrgIDs.Add(60);
BindGridView(60, OrgIDs);
我正在使用 Mysql 数据库
【问题讨论】:
标签: c# asp.net recursion recursive-query