Click here to Skip to main content
15,911,039 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,
I am using following code to save my data to database Where does the statement to save a picture in the database fit?

VB
Dim drNewRowMCQsAns As DataRow
        drNewRowMCQsAns = DsResultSaveNow.tblResult.NewRow

        drNewRowMCQsAns.Item("PaperID") = vrPaperIDInitialized
        drNewRowMCQsAns.Item("StudentID") = vrStudentID
        drNewRowMCQsAns.Item("StudentName") = vrStudentName

        DsResultSaveNow.tblResult.Rows.Add(drNewRowMCQsAns)
        taResultSaveNow.Update(DsResultSaveNow.tblResult)



I have image field in the database but how to save an image?
Thanks
Posted

You haven't posted enough information to really help you. The code you posted doesn't really seem to have anything to do with loading a picture into a database...it looks like you are just saving a couple of string or number fields. Try reading some of the CP Articles[^] for help, or post more information.

(Here[^] is another CP Articles search with different keywords that might help)
 
Share this answer
 
v2
Comments
RaviRanjanKr 28-Jul-11 13:13pm    
5+
Save the image to a MemoryStream object, and pass MemoryStream.GetBuffer() as a parameter to your stored procedure.
 
Share this answer
 
This code sample in C# (will be not difficult to convert in VB.NET) works well to read images from database and bind dataset with a gridview control.
To get image from gridview and save it in file use MemoryStream Object like here:
VB
'Initialize image variable
 Dim newImage As Image
 'Read image data into a memory stream
 Using ms As New MemoryStream(imageData, 0, imageData.Length)
  ms.Write(imageData, 0, imageData.Length)
  'Set image variable value using memory stream.

     newImage = Image.FromStream(ms, True)
  'Store selected image to a local file in current directory:
     newImage.Save(".\picture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
 End Using
 
Share this answer
 
v2

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