I am using SQL Server 2008 r2 database and Winform C# 2010. In my table I am able to save image from Winform. But when I tried to view this image, there was an error showing.
Table is
CREATE TABLE [dbo].[tbl_Image](
[ID] [char](7) NOT NULL,
[Photo] [image] NULL)
and data in this table is
I am trying to show this photo in piturebox by using bellow code
SqlConnection con;
SqlDataAdapter adapter;
DataSet ds; int rno = 0;
MemoryStream ms;
byte[] photo_aray;
con = new SqlConnection("user id=sa;password=123;database=dbTest");
adapter = new SqlDataAdapter("select [ID],[Photo] from [tbl_Image] WHERE [ID]='0321253'", con);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
ds = new DataSet(); adapter.Fill(ds, "student");
if (ds.Tables[0].Rows.Count > 0)
{
pictureBox2.Image = null;
if (ds.Tables[0].Rows[rno][4] != System.DBNull.Value)
{
photo_aray = (byte[])ds.Tables[0].Rows[rno][1];
MemoryStream ms = new MemoryStream(photo_aray);
pictureBox2.Image = Image.FromStream(ms);
}
}
else
MessageBox.Show("No Records");
but it is giving error "Parameter is not valid." in the line pictureBox2.Image = Image.FromStream(ms)
How can I solve this?