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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Parveen SiwachRank #6,758 · 257 reputationPosted May 21, 2013, 1:17 AM EDT
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")
Pankaj PandeyRank #642 · 3.7K reputationPosted May 21, 2013, 1:23 AM EDT
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