0

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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by baladeveloper
0

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();
     }
}
0

Hi Mitja Bonca.

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

By Balas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.