?
Solved

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

Posted on 2011-10-10
10
Medium Priority
?
117 Views
Last Modified: 2015-06-23
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

 
0
Comment
Question by:SweetsJamRock
8 Comments
 
LVL 14

Assisted Solution

by:nishant joshi
nishant joshi earned 1000 total points
ID: 36946670
have you use blob or clob in your database?

or you want to strore only path.?


0
 
LVL 13

Expert Comment

by:Naman Goel
ID: 36946887
0
 
LVL 9

Expert Comment

by:dexterrajesh
ID: 36946938
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:SweetsJamRock
ID: 36947428
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
 

Author Comment

by:SweetsJamRock
ID: 36947797
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
 

Author Comment

by:SweetsJamRock
ID: 36947799
0
 

Author Comment

by:SweetsJamRock
ID: 36947802
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 1000 total points
ID: 36948467
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question