我收到以下錯誤;與此命令關聯的DataReader必須先關閉
「已經有一個打開的DataReader與這個Command關聯,必須先關閉它。」
是因爲我在foreach循環中使用了讀取器嗎?或者問題可能是什麼? 問候 BK
foreach(Apple a in listApple)
{
....
using (SmartSqlReader reader = Db.CurrentDb.ExecuteReader(sp))
{
while (reader.Read())
{
a.blablabla += reader.GetInt32("BLA_BLA_BLA");
}
}
.....
}
這是我的錯誤。我在深入調查中發現它。 我一直在使用if(reader.Read())而不是使用using和whil循環。 全部解決。 謝謝 bk – theklc 2009-10-22 13:07:51