Raj mca

Raj mca

  • NA
  • 3
  • 1.7k

How to display multiple images from sql server 2005 into c#

Mar 27 2013 12:13 AM
I STORED MULTIPLE IMAGES IN MY SQL SERVER 2005. NOW I WANT TO RETRIEVE PARTICULAR CATEGORY OF IMAGES INTO MULTIPLE PICTUREBOX AT RUNTIME IN C# WINDOWS APPLICATION. i used the following code in my final result form at form_Load using c# windows apps.. But it displays only one picture at run time pls help to me...



  1.  
  2.  
  3. SqlConnection con = new SqlConnection(@"Data Source=ttt-PC;Initial Catalog=Query_Image;Integrated Security=True");
  4.             SqlCommand cmdnew = new SqlCommand("select pic from Image_Category where IMG_Cat='" + searchvalue.ToString() + "'", con);
  5.             con.Open();
  6.           //  SqlDataReader dr = cmdnew.ExecuteReader();
  7.             SqlDataAdapter da = new SqlDataAdapter(cmdnew);
  8.             DataSet ds = new DataSet("Image_Category");
  9.             byte[] mydata = new byte[0];
  10.             da.Fill(ds, "Image_Category");
  11.             DataRow myrow;
  12.             //if (dr.HasRows)
  13.             //{
  14.             //    while (dr.Read())
  15.             //    {
  16.  
  17.             for (int i = 0; i < 2; i++)
  18.  
  19.             // while (i <= dt.Rows.Count)
  20.  
  21.             {
  22.  
  23.                 myrow= ds.Tables["Image_Category"].Rows[i];
  24.                 mydata = (byte[])ds.Tables[0].Rows[i]["pic"];
  25.                 str[i]=new MemoryStream(mydata);
  26.  
  27.                 pbx[i]=new PictureBox();
  28.                  pbx[i].Size = new Size(150, 150);
  29.                  pbx[i].SizeMode = PictureBoxSizeMode.StretchImage;
  30.                 pbx[i].BackgroundImage = Image.FromStream(str[i]);
  31.                  pbx[i].Visible = true;
  32.                  //this.Controls.Add(pbx[i]);
  33.                 }
  34.  


PLEASE TELL IS IT ANY WRONG WITH THIS CODE?
OR SUGGEST NEW CODE TO ME PLEASE..

its very urgent