-1

im new to c#, can somone please tell me how to add image to database, from picture box using c#. i have a registration form which user is added to database(SQL 2008), but i have no idea how to add image of the user to database, which contain many columns of user information and a column of picture. sql<2008> visual studio <2010>

Alexander
  • 3,129
  • 2
  • 19
  • 33
  • Read the image after upload, and make a binary string and then you can set this string in the database column. – Atul Darne Feb 17 '14 at 08:49
  • this is definetely a clone, it was asked so much, that i really do not want to search for colneables, it is soo boring. why you did not read the FAQ about using this site? – Alan Turing Feb 17 '14 at 13:31
  • to admins: you definetely might add the phrase "i have no idea how to add image of the user to database" to blacklisted phrases list, really – Alan Turing Feb 17 '14 at 13:33

3 Answers3

1

You should have a binary field in DB for that. Read your image like binary array and save in into DB. But It is not goog practice as for me. I usually save image in cloud or folder and in DB - only URL

Community
  • 1
  • 1
melvas
  • 2,346
  • 25
  • 29
0

create table IMAGELOAD (img1 binary)

while saving send path of the file to this field

Suggestion : Instead saving image into database.Save in application folder.

Revan
  • 1,104
  • 12
  • 27
0

Can you be more specific? What you don't know how to do? How to get image from pictureBox? This can help you, hope.

//Save content of imageBytes to db VARBINARY(MAX) 
byte[] imageBytes;
using (imgStr = new System.IO.MemoryStream())
{
    pictureBox.Image.Save(imgStr, System.Drawing.Imaging.ImageFormat.Jpeg); // Depending on your format.
    imageBytes = imgStr.ToArray();
}

//to load from db use
using (Stream imgStr = new MemoryStream(imageBytes))
{
    pictureBox.Image = System.Drawing.Image.FromStream(imgStr);
}
Jaroslav Kubacek
  • 1,387
  • 18
  • 26