已经有一个与此命令关联的打开DataReader,必须先关闭它。并在数据库中检索多个图像? [英] There is already an open DataReader associated with this Command which must be closed first. and retrieve multiple images in database?

查看:77
本文介绍了已经有一个与此命令关联的打开DataReader,必须先关闭它。并在数据库中检索多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while (sqldread.Read())
           {
               int Dbid = (int)sqldread["Id"];


               Label4.Text = Convert.ToString(Dbid);
               if (Dbid != null)
               {

                   String QueryStr = "SELECT Image FROM User_Images WHERE Id='" + Dbid + "'";
                   scmd1 = new SqlCommand(QueryStr, con);
                   scmd1.CommandType = CommandType.Text;
                   scmd1.Connection = con;
                   SqlDataReader sqldread2 = scmd1.ExecuteReader();
                   while (sqldread2.Read())
                   {
                       Context.Response.BinaryWrite((byte[])sqldread2["Image"]);
                       Context.Response.ContentType = "image/jpg";

                       al.Add(sqldread2);
                       sDatAdp.SelectCommand = scmd1;

                       DataList1.DataSource = sqldread2;
                       DataList1.DataBind();
                   }
               }
               sqldread.Dispose();
           }
       }





已经有一个与此命令关联的开放DataReader必须先关闭。

它在SqlDataReader中显示sqldread2 = scmd1.ExecuteReader();



根据场景,我需要检查输入值是否等于第一个table

如果它等于那么它将被添加到int变量

并且根据该特定变量我们可以得到数据库中与该id相关的所有图像。



There is already an open DataReader associated with this Command which must be closed first.
it shows in SqlDataReader sqldread2 = scmd1.ExecuteReader();

according to the scenario , i need to check input value equals with the first table
if its equal then it will be added to the int variable
and according to that particular variable we can get all the images on the database which related to that id.

推荐答案

如果您尝试在该查询打开阅读器时对数据进行数据绑定,SQL会抱怨 - 因为它不能同时执行两项操作。



我怀疑你想重新考虑你的代码,因为在循环中有一个数据绑定是没有意义的......
If you try to databind a query while you have a reader open on that query, SQL will complain - because it can't do two things at once.

I suspect that you want to re-think your code, since it is rather pointless to have a databind in a loop...


这篇关于已经有一个与此命令关联的打开DataReader,必须先关闭它。并在数据库中检索多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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