how to upload image in database(not path) in vb.net window
how to upload image in database(not path) in vb.net window application
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj PandeyPosted May 21, 2013, 5:23 AM
convert image into binary data and save it in database also save extension on that image .
i have code to convert into binary and from binary to image, but it is in C#, but there are many website who convert c# to vb and vb to C#.
there you can convert this code into vb and use it.
http://www.c-sharpcorner.com/Blogs/11642/convert-image-into-a-binary-file-and-save-in-txt-file.aspx
Mark as answered if usefull
Parveen SiwachPosted May 21, 2013, 5:17 AM
Go through this video tutorial, this will help you to solve your issue:
http://www.youtube.com/watch?v=o5XboEfKGMY
Also, you can try following code to "Save" Image in database:
Dim con As New SqlConnection _
("Server=YourServer;uid=
Dim da As New SqlDataAdapter _
("Select * From MyImages", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim fs As New FileStream _
("C:\winnt\Gone Fishing.BMP", FileMode.OpenOrCreate, _
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
con.Open()
da.Fill(ds, "MyImages")
Dim myRow As DataRow
myRow = ds.Tables("MyImages").NewRow()
myRow("Description") = "This would be description text"
myRow("imgField") = MyData
ds.Tables("MyImages").Rows.Add(myRow)
da.Update(ds, "MyImages")
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
MsgBox ("Image saved to database")
and "Retrieve" Image from database:
Dim con As New SqlConnection _
("Server=YourServer;uid=
Dim da As New SqlDataAdapter _
("Select * From MyImages", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
con.Open()
da.Fill(ds, "MyImages")
Dim myRow As DataRow
myRow = ds.Tables("MyImages").Rows(0)
Dim MyData() As Byte
MyData = myRow("imgField")
Dim K As Long
K = UBound(MyData)
Dim fs As New FileStream _
("C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, _
FileAccess.Write)
fs.Write(MyData, 0, K)
fs.Close()
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
MsgBox ("Image retrieved")