【发布时间】:2025-11-29 10:35:01
【问题描述】:
我收到以下错误;
“已经有一个打开的 DataReader 与此命令关联,必须先关闭。”
是因为我在 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 和 while 循环。都解决了。谢谢bk
标签: c# sql sqldatareader