Click here to Skip to main content
15,944,733 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I use

qry = ""
qry = "SELECT TOP 1 Image FROM T_ImageStore"
cmd = New OleDbCommand(qry, conn)
Dim img As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
Dim ms As MemoryStream = New MemoryStream(img)
PictureBox1.Image = Image.FromStream(ms)

this code to retrieve image from database and display in picture Box.

I get an error when PictureBox1.Image = Image.FromStream(ms) line encounted

The bug is

An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll

Additional information: Parameter is not valid.

I couldn't find what the error is, Can any 1 help in this pls,

Thava Rajan 13-Nov-13 4:39am    
seems there might be a data loss at the time of insert or update,or else is this happens for the first image or when the second image loaded

void DispalyImage()

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "Images");
        int count = ds.Tables["Images"].Rows.Count;

        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            var data = (Byte[])(ds.Tables["Images"].Rows[count - 1]["Image"]);
            MemoryStream stream = new MemoryStream(data);
            pictureBox1.Image = Image.FromStream(stream);

Share this answer
Dim myMS As New IO.MemoryStream

PictureBox1.Image = System.Drawing.Image.FromStream(myMS)

I hope, It will help for you........
Share this answer

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