Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add some images to my database table.How can I do that(How to convert images into binary). Give me an answer with an example.with a small example application.
Posted
Updated 4-Dec-12 16:27pm
v2

Assuming you are using SQL Server as the database, here are some links that might help you.
You can use the image column.

Try
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]
Store or Save images in SQL Server[^]
http://www.mindstick.com/Blog/184/Save%20image%20in%20SqlServer%20usin[^]
 
Share this answer
 
Comments
Espen Harlinn 11-Dec-12 17:53pm    
5'ed!
Abhinav S 12-Dec-12 0:52am    
Thank you Espen.
Wendelius 12-Dec-12 1:21am    
So true :)
To add to Abhinav's answer, if you want to use FileStream for the images, have a look at How to store and fetch binary data into a file stream column[^]
 
Share this answer
 
Comments
Espen Harlinn 11-Dec-12 17:53pm    
5'ed!
Wendelius 12-Dec-12 0:16am    
Thanks :-)
Abhinav S 12-Dec-12 0:52am    
5 of course!
Wendelius 12-Dec-12 1:22am    
Thanks :)
Dear Nishantha,

I hope that you are using SQL Server to store the images. Here is the code that I use in my project to insert profile pictures to the Database.

C#
string FileName = "";
Byte[] img = new byte[0];

FileDialog filedialog = new OpenFileDialog();
filedialog.ShowDialog();
FileName = filedialog.FileName;
yourPictureBox.ImageLocation = FileName;

if (FileName.Length > 0)
{
    FileStream fs = new FileStream(FileName, FileMode.Open);
    img = new Byte[fs.Length];
    fs.Read(img, 0, (int)fs.Length);
    fs.Close();
}


Kushan Randima
Software Engineer
DigiteQ Solutions PVT LTD
 
Share this answer
 
v2
Comments
NISHAN SANDEEPA 6-Dec-12 2:06am    
Thank you Mr Kushan......

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