Hi Friends

I want to set the image to picture box from get sql.

I wrote this coding , But Its not Working Properly .

byte[] mydata=new byte[0];
mydata=(byte[])dt.Rows[0]["img"];
int arraysize=mydata.GetUpperBound(0);

MemoryStream stream = new MemoryStream(mydata,0,arraysize);
img.Image = Image.FromStream(stream);

where i wrote wrongly Please tell ..

Thanks in Advance :)

Recommended Answers

All 2 Replies

Hi,
check this out:

private void viewSnapShotButton_Click(object sender, EventArgs e)
{
     string connectionString = ConfigurationManager.AppSettings["myCconnectionSstring"];
     string queryString = ConfigurationManager.AppSettings["MyQueryString"];
     SqlConnection connection = new SqlConnection(connectionString);
     try
     {
          connection.Open();
          SqlCommand command = new SqlCommand(queryString, connection);
          byte[] image = (byte[])command.ExecuteScalar();
          MemoryStream ms1 = new MemoryStream(image);
          pictureBox1.Image = Bitmap.FromStream (ms1);  
          ms1.Close();
     }
     finally
     {
          connection.Close();
     }
}

Hi Mitja Bonca.

Now Also Its Said 'Parameter is not valid.' Its Error Has Appear at Memory stream .

By Balas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.