Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Dear All ,

I have one textbox1 and one picturebox , i need to retrive the image from database and display this image in picturebox.

my code is given below....

C#
private void textBox1_TextChanged(object sender, EventArgs e)
       {
             if (textBox1.TextLength == 4)
               {
                   SqlConnection ConnCMS = new SqlConnection();
                   string SqlConnectionString;
                   SqlConnectionString = "Server=10.1.1.28; Database=cms;uid=sa; pwd=samesame;";
                   ConnCMS.ConnectionString = SqlConnectionString;
                   SqlCommand cmdSelect = new SqlCommand("select FingerImage from EmployeeFinger where EmployeeNo=@ID", ConnCMS);
                   cmdSelect.Parameters.Add("@ID", SqlDbType.NVarChar).Value = textBox1.Text;
                   SqlDataAdapter sqlDA = new SqlDataAdapter(cmdSelect);
                   DataSet ds = new DataSet();
                   sqlDA.Fill(ds, "EmployeeFinger");
                   int c = ds.Tables["EmployeeFinger"].Rows.Count;
                   if (c > 0)
                   {
                       Byte[] byteBLOBData = new Byte[0];
                       byteBLOBData = (Byte[])(ds.Tables["EmployeeFinger"].Rows[0]["FingerImage"]);
                       MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
                       pictureBox1.Image = Image.FromStream(stmBLOBData);

                   }
                   ConnCMS.Close();
               }
           }


but its give me the Error "Parameter is not valid" at the last line pictureBox1.Image = Image.FromStream(stmBLOBData);

please help me

thanks
Posted
Updated 25-Dec-11 0:42am
v2

Check the code you used to save the image in the first place - it sounds like it dislikes the data format.
Certainly the convert code looks just like the code I use, so it should work if the data is correct.
 
Share this answer
 
Comments
PravinkNair 9-May-12 1:44am    
I am also getting the same error... can pls. help me with the same....
OriginalGriff 9-May-12 3:44am    
Did you check as I suggested to vaquas?
use a handler to retrieve an image.
 
Share this answer
 
Comments
PravinkNair 9-May-12 1:45am    
wht type if handlers are u talking abt.....

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