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.
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"
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.
'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