与此命令关联的 DataReader 必须先关闭 [英] DataReader associated with this Command which must be closed first

查看:33
本文介绍了与此命令关联的 DataReader 必须先关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误;

已经有一个与此命令关联的打开的 DataReader,必须先关闭它."

"There is already an open DataReader associated with this Command which must be closed first."

是不是因为我在 foreach 循环中使用了阅读器?或者可能是什么问题?问候黑

is it because I have used the reader in foreach loop ? or what the problem might be ? Regards BK

foreach( Apple a in listApple )
{


....
                   using (SmartSqlReader reader = Db.CurrentDb.ExecuteReader(sp))
                    {
                        while (reader.Read())
                        {
                            a.blablabla += reader.GetInt32("BLA_BLA_BLA"); 
                        }
                    }


.....

}

推荐答案

尝试以下操作:

using (SmartSqlReader reader = Db.CurrentDb.ExecuteReader(sp))
 {
  while (reader.Read())
  {
   a.blablabla += reader.GetInt32("BLA_BLA_BLA"); 
  }
  reader.Close();
 }

这篇关于与此命令关联的 DataReader 必须先关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆