how do i save an image to a table using c#

Hey Guys,

  I AM DOING A DESKTOP APPLICATION

i am stUck with a problem.  i have develope A major application and i can not seem to
 be able to save a picture from a picture box object to my table  using c#

I just need the syntax.  
 
    example:  if i am saving  from a textbox object to a table i would use this syntax
 
        myanswer=textbox1.text;

  i need the syntax to be as simple as that if possible

 
SweetsJamRockAsked:
Who is Participating?
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, first you need a column in your table that can store this kind of data, in your table use varbinary(MAX) as your column data type, then in your project sync your data schema to reflect this change in your data objects (LINQ to SQL), now the property of your object that will match that column must be of type byte[], to set its value you first need to save your image into a byte[] array, in this way:
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
    pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    myEntityObject.MyImageColumn = ms.ToArray();
}

Open in new window


I hope be clear enough.
0
 
nishant joshiTechnology Development ConsultantCommented:
have you use blob or clob in your database?

or you want to strore only path.?


0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
dexterrajeshCommented:
hi,

if the DB type for the image column is blob you can convert the image object to a byte array and insert it to the DB.

E.g: http://www.codeproject.com/KB/aspnet/ImageInDatabase.aspx 
0
 
SweetsJamRockAuthor Commented:
guys i am using sql 2008, there is no "BLOB" type in there.  however i see bit, so i will try that.  I had also check the both areas that was sent to me via link.  

i need some more help guys.  i can't have my application stuck because of this 1 problem.

oh! - also i am not interested in saving the path in the table ONLY the picture (image).  

the user must be able to change the picture any time and resave picture changes.

thanks anyway
0
 
SweetsJamRockAuthor Commented:
guys i have seen many ways of doing this thing but i want you guys to take a look at what i have and see
 
   this is a screen of a picture i want to save after i have retrieved the image

 


THIS IS THE METHOD THAT SELECT THE PICTURE


 THIS IS THE SYNTAX THAT WOULD HAVE SENT D IMAGE TO THE TABLE OF IT WAS correct.

This is the ONLY problem

  contextdbobject.tablename.insertonsubmit(sldl);
  contextdboject.submitchanges();
 this is the method
0
 
SweetsJamRockAuthor Commented:
0
 
SweetsJamRockAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.