Click here to Skip to main content
15,886,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
MemoryStream mstream = new MemoryStream(img);
pictureBox1.Image = System.Drawing.Image.FromStream(mstream);
At the second line i have to face an exception that invalid parameter.Kindly help me.
my field data type is blob and i have to show this picture in c# project.
Posted

See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it's Sql Server based, but it's exactly the same problem (and solution) with MySql.
 
Share this answer
 
Comments
Asim Shahid 19-Sep-14 15:56pm    
i am facing still problem exception parameter is not valid is generated.
OriginalGriff 19-Sep-14 16:26pm    
And did you read the bit at the bottom?
"Before I close...
No, you can't retrieve the image data for the images you already stored wrongly - you will have to delete them all, and save them to the DB correctly!"

Because if you didn't...
C#
string query1 = "Select * from members where ID='";
           query1 = query1 + txtid.Text + "'";
           cmd = new MySqlCommand(query1, con);
           MySqlDataReader d1 = cmd.ExecuteReader();
           while (d1.Read())
           {
               try
               {
                   byte[] data = (byte[])d1["image"];
                   using (MemoryStream stream = new MemoryStream(data))
                   {
                       pictureBox1.Image = new Bitmap(stream);
                   }
 
Share this answer
 
Do have a look at the following article.

Display Images from SQL server

I hope it will solve your problem. :)
 
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