954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to save image into database

what is control that i should use to save image into my database

Sin Savada
Newbie Poster
1 post since Jul 2007
Reputation Points: 10
Solved Threads: 0
 
manal
Junior Poster
122 posts since Mar 2006
Reputation Points: 37
Solved Threads: 17
 
what is control that i should use to save image into my database

I have attached a small demo project for reading and writing a image in a database. It was developed in VS 2003. Have a look at it and modify it according to your own needs.

Attachments VB.NET_-_Data_Access_-_Read_and_Write_Images_from_a_Database_.zip (144.11KB)
arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

More on thread
I want information on how to save images into the database and retrive the images into their various picture boxes using visual basic code in windows form.

Ajayi Taiwo O.
Newbie Poster
2 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

can you assist me ?
I want to use vb.net to write a code that will save data into an sql server database and retrive it to a picturebox.
thanks

Ajayi Taiwo O.
Newbie Poster
2 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

hi
i think u can't save apicture as apictur in database but u can save the link in database and u can call the picture by acommand or any call sentance


ex
if u save apicture in c:\test\p1.jpg
and
u save this path in database

u can
create acommand to Retriev the path
and change the url of image to the path
like
image.url="path"

i hope help u

rami2005
Newbie Poster
12 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Really thanks very much for the sample program.i really happy with the program i just learn the SQL server. like these program is very very useful to me.

Rajhumaar
Newbie Poster
1 post since May 2008
Reputation Points: 10
Solved Threads: 0
 
lal.ramesh
Newbie Poster
10 posts since Nov 2010
Reputation Points: 19
Solved Threads: 0
 
'Save an Image to a memory stream so you can get the bytes
        Dim sampleImage As Bitmap = New Bitmap(100, 100)
        Dim mStream As New System.IO.MemoryStream
        Dim ImageBytes As Byte()

        sampleImage.Save(mStream, Imaging.ImageFormat.Png)
        ImageBytes = mStream.ToArray

        'Sample Insert image command
        'Save the bytes from the image into a image or varbinary column
        Dim com As New SqlClient.SqlCommand("Insert Into MyTable" & vbCrLf & _
                                            "(MyImageColumn)" & vbCrLf & _
                                            "Values(@MyImage)")

        'an image column or varbinary column
        com.Parameters.Add("@MyImage", SqlDbType.Image)
        com.Parameters("@MyImage").Value = ImageBytes


        'Sample Read Image Command
        'Read the bytes from the table and create a new memory stream from them
        com.CommandText = "Select MyImage From MyTable"
        Dim rdr As System.Data.SqlClient.SqlDataReader

        rdr = com.ExecuteReader
        If rdr.Read Then
            Dim newMstream As New System.IO.MemoryStream(CType(rdr.Item("MyImage"), Byte()))
            'Create a new image from the bytes from the memory
            Dim ImageFromDB As New Bitmap(newMstream)

        End If
Unhnd_Exception
Posting Pro
571 posts since Nov 2010
Reputation Points: 249
Solved Threads: 201
 

Friends! Do not resurrect old threads. This thread is quite old (3 years).

Thread closed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You