我想獲取一個值列表,當我得到一個值後,我傳遞該值並調用相同的方法。遞歸循環缺少c中的第一個值#
如果結構就像
60
|
61
|
63
|
64
代碼工作正常,返回所有值當我通過60
但是當結構就像是
60
| |
61 63
|
62
所以這裏61和63的父母ID是60.
然後組織ID傳遞到第一個前ecution是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 [email protected]";
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數據庫
你能告訴我一些代碼嗎?謝謝 – Mark
我已經添加了它:-) –