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

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.

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.

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

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

u can
create acommand to Retriev the path
and change the url of image to the path

i hope help u

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.

Member Avatar


'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 & _

        '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

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

Thread closed.


 CREATE TABLE [dbo].[imgtable](
      [id] [int] NULL,
      [img] [image] NULL

Code :

        Dim cmd As New SqlCommand("insert into imgtable (id,img) values ( @id,@img)", cnn)
        cmd.Parameters.AddWithValue("@id", id)
        cmd.Parameters.AddWithValue("@img", content)

source: Store image in database - vb.net