.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

How to show image from sql db to picture box in c# winforms

Posted By: Chandranshu Awasthi     Posted Date: May 19, 2011    Points:5   Category :C#
i have a image which is stored in binary data in sql db....i want to show the imge in picture box of my form

cn anyone help me pls...

Author: Chandranshu Awasthi             
Posted Date: May 19, 2011     Points: 20   

i m using this code

Byte[] img = new Byte[0];
dr = ds.Tables[0].Rows[0];
img= (byte[])dr["myimage"];
MemoryStream aashu = new MemoryStream(img);
aashu.Write(img, 0, img.Length);
aashu.Position = 0; !
PictureBox1.Image = Image.FromStream(aashu); // error in this line

here i am getting an error "Parameter is not valid"

Author: Dhiraj Ranka             
Posted Date: May 20, 2011     Points: 20   


You can try this tutorial


Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com
Author: Chandranshu Awasthi             
Posted Date: June 01, 2011     Points: 20   

hi Dhiraj

i have used the same code but it is not taling where condition while retrieving the image

SqlCommand cmd = new SqlCommand("Select myimage from image where id=26" , con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "image");
int c = ds.Tables["image"].Rows.Count;
if (c > 0)
Byte[] img = new Byte[0];
img = (Byte[])(ds.Tables["image"].Rows[c - 1]["myimage"]);
MemoryStream aashu = new MemoryStream(img);
pictureBox1.Image = Image.FromStream(aashu);

see if i am using id =26 its coming but if i use id='"+convert.toint32(textbox.text)+"' it is not coming

Author: cathyhill345             
Posted Date: April 14, 2014     Points: 20   

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend