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

Recommended Answers

All 10 Replies

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.

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.
thanks

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

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 for Unhnd_Exception
'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

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

Thread closed.

Table:

 CREATE TABLE [dbo].[imgtable](
      [id] [int] NULL,
      [img] [image] NULL
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

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)
        cmd.ExecuteNonQuery()

source: Store image in database - vb.net

winston

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.