Click here to Skip to main content
16,018,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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
Posted
Updated 5-Jul-13 20:11pm
v6

1 solution

Check your query here your missing the '=' sign after where id check it in your code fix it like this
C#
String QueryStr = "SELECT Image FROM User_Images WHERE Id='" + Dbid + "'";
 
Share this answer
 
Comments
promod madushan 6-Jul-13 0:49am    
@Zafar Safi
how i view serveral images at once for above scenario?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900