I wrote the following code to transfer an image from a database to a picure window in C #. I got this code from microsoft. Where is the URL of this page. Microsoft
When I run this code, the display parameter is not a valid exception.
What is wrong with this code?
private void button2_Click(object sender, EventArgs e) { try { String strCn =@ "Data Source=DESKTOP-ROF2H0M\BHAGI;Initial Catalog=Golden;Integrated Security=True"; SqlConnection cn = new SqlConnection(strCn); cn.Open(); //Retrieve BLOB from database into DataSet. SqlCommand cmd = new SqlCommand("SELECT User_id ,img FROM login", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "login"); int c = ds.Tables["login"].Rows.Count; if (c > 0) { //BLOB is read into Byte array, then used to construct MemoryStream, //then passed to PictureBox. Byte[] byteBLOBData = new Byte[0]; byteBLOBData = (Byte[])(ds.Tables["login"].Rows[c-1]["img"]); MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); pictureBox1.Image = Image.FromStream(stmBLOBData); } cn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
The following error message has appeared.
An unhandled exception of type "System.ArgumentException" occurred in System.Drawing.dll
Additional Information: The parameter is not valid.
Here is the binding of my database. LOgin table
source share