Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button1_Click(object sender, EventArgs e)
{
    cm = new SqlCommand("select photo from pqr where Id='abc'", cn);
    SqlDataReader rd = cm.ExecuteReader();

    if (rd.Read())
    {
        byte[] b = (Byte[])rd["photo"];
        MemoryStream ms = new MemoryStream(b);
        pictureBox1.Image = Image.FromStream(ms);//here error is occurred parameter is not Valid
    } rd.Close();
}
}


[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v2
Comments
Bernhard Hiller 11-Sep-14 2:16am    
What's the datatype of the photo column in the database?
How many bytes did you get into byte[b]?
Is it really an image which was saved into that column or something else (e.g. a pdf)?

C#
Always Use Handler Class to Getting Image from Database. 
So i want Suggest to use this link to Solve your Problem

http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers.5[^]
 
Share this answer
 
Refer - Image.FromStream: Parameter not valid[^].

You might have to convert to Bitmap and then use that.
 
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