本文介绍了执行读者错误? SQLexecutereader没有标识?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlConnection con = new SqlConnection();
     con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";



     SqlCommand scmd1 = null;
     SqlDataAdapter sDatAdp = new SqlDataAdapter();

     String selQuery = "SELECT Id FROM MapDataImage WHERE Source='" + TextBox1.Text + "';";
             {

             SqlCommand scmd = new SqlCommand(selQuery, con);

             con.Open();

             SqlDataReader sqldread = scmd.ExecuteReader();

             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);

                 }
             }

             sqldread.Dispose();
             //scmd1.CommandType = CommandType.Text;
             //scmd1.Connection = con;

         SqlDataReader dr = scmd1.ExecuteReader();
         dr.Read();
         Context.Response.BinaryWrite((byte[])dr["Image"]);
         Context.Response.ContentType = "image/jpg";

         sDatAdp.SelectCommand = scmd1;


         GridView1.DataSource = dr;
         GridView1.DataBind();

         con.Close();
         dr.Close();
         sDatAdp.Dispose();
         con.Dispose();
 }





通过在查询中添加=解决



solved by adding "=" to query

推荐答案

String QueryStr = "SELECT Image FROM User_Images WHERE Id='" + Dbid + "'";


这篇关于执行读者错误? SQLexecutereader没有标识?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 02:34