Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am developing a information system and I have to store the images of the persons, tell me how should I do that. I have tried to insert the images in sql server directly but after that I'm not able to retrieve them. What should I do
Posted
Updated 13-Jan-10 1:30am
v2

I would suggest not to store the image in the sql-server but rather the path where the image is stored on the hard drive (if needed copy the image to a network share)

Inserting images into your database will only cause it to grow extremely fast.
 
Share this answer
 
Hi,

Check the below URL:

http://aspalliance.com/articleViewer.aspx?aId=138&pId=[^]

Hope you will get the solution of your problem.

Thanks
Mehul Thakkar
 
Share this answer
 
--image_data is an IMAGE field           
SqlCommand cmd = new SqlCommand("SELECT image_data FROM GRAPHIC WHERE ID = 5", cn);

--Load into Byte Array
byte[] b = (byte[])cmd.ExecuteScalar();
MemoryStream ms = new MemoryStream(b);

--Load stream into an image object
Image img = Image.FromStream(ms);
pictureBox1.Image = img;
 
Share this answer
 
hi try this code


1.) make attribute picture type nvarchar(100)
2.) make img folder in website folder
3.) take file upload control fileupload1

<b>Insert image in Database</b>:

if(fileuplaod1.filename!=null)
{
fileupload1.savefileAs(server.mapPath("img//")+fileupload1.filename.tosting());//this will save your image in img folder
String path=fileuplaod1.filename.tostring();
}
//then execute insert query like

string query="insert into <table name> values ('"+tztbox1.text+"',....,'"+path+"')";
//this query will save your img path or image name in your database.


<b>Retrive image from the database:</b>

String str="select * from <Table name>";
com=new sqlcommand(str,connection);
Sqldatareader rd=com.executeReader();
Image1.imagerl=server.mapPath("img//")+reader["picture"].toString();



IF you get your answer then please give me marking/rating

thanks
 
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