我想執行mysql內循環查詢,每次得到新的結果。我面臨的問題是,循環僅在第一次成功循環,第二次說明。這意味着如果它的idcount爲5,它只會變爲1,當它進入2時,會出現錯誤。循環只循環一次,請幫忙找到解決方案C#,MySQL
無效嘗試讀取調用之前訪問一個字段()
正是在這一行 「串RESULT2 = mysqlReader5 [0]的ToString();」
這將是很好的你如果你能幫助我做出這個成功的循環
Thanx提前。
for (int i = 0; i < idcount; i++)
{
connection.Open();
string x = idarray[i];
ImageLoop img = new ImageLoop();
image[i] =img.imageloop(x);
MySqlCommand mysqlCmd5 = new MySqlCommand("SELECT image FROM useralbum where user_id='" + x + "' LIMIT 0,1;", connection);
MySqlDataReader mysqlReader5 = mysqlCmd5.ExecuteReader();
while (mysqlReader5.Read())
{
}
string result2 = mysqlReader5[0].ToString();
image[i] = result2;
connection.Close();
}
價值,但那麼,爲什麼它的工作的第一環,而不是爲別人。 – 2013-02-13 05:45:46
@Amalan,你怎麼說,只要你在第一次循環for循環 – Habib 2013-02-13 05:48:58
到達'string result2 = mysqlReader5 [0] .ToString();'這行是爲web服務該錯誤指示了這一行中的問題。另外,當我添加斷點並檢查數組的第一個值是從數據庫中檢索的。 這是指示它「在c:\ Users \ Amalan \ Documents \ Visual Studio 2010 \ WebSites \ Amalan \ App_Code \ ArrayDetails.cs:line 156」 – 2013-02-13 05:51:55