Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading and Retrieving images from the database using VB.net

Status
Not open for further replies.

krotha

Programmer
Nov 5, 2000
116
US
In my present project I am using VB.net with SQL Server2000.(It is a Client Server not web based)
How to uplaod the images into the database.
How to retrieve the image from the database into a picturebox.
Someone having an idea, in this regard is most welcome.
 
if the image is embedded in the database it is probably binary. You have to create a temp binary file from the data read in from the database, then you load that into the image in your picture box.

hope that that gives you some ideas.
 
this is a question I started looking for answer too and has been bugging me since yesterday.. Finally found out how to make it work.

Your answer could look something like ..

Dim dA As New SqlClient.SqlDataAdapter("SELECT BLOB FROM BLOBS", cn)
Dim dt As New DataTable
Dim x As Image
dA.Fill(dt)
Dim bytImage(dt.Rows(0)(0).length - 1) As Byte
bytImage = dt.Rows(0)(0)
Dim memStream As New IO.MemoryStream(bytImage)
PictureBox1.Image = Image.FromStream(memStream) 'Image.FromFile("C:\Documents and Settings\Administrator\My Documents\My Pictures\InDotLogoB.jpg")

 
Opps here is the save to the database...

Dim fs As New IO.FileStream("C:\Documents and Settings\Administrator\My Documents\My Pictures\InDotLogoB.jpg", IO.FileMode.Open, IO.FileAccess.Read)
Dim imageData(fs.Length) As Byte
Dim intlen As Integer = fs.Length

Dim cn As New SqlClient.SqlConnection("server=(local);database=blobstuff;trusted_connection=yes")


fs.Read(imageData, 0, fs.Length)
fs.Close()
Dim cm As New SqlClient.SqlCommand("AddBlob", cn)
cm.Parameters.Add("@blob", SqlDbType.Image)
cm.Parameters("@blob").Direction = ParameterDirection.Input
cm.Parameters("@blob").Value = imageData
cm.CommandType = CommandType.StoredProcedure
cn.Open()
cm.ExecuteNonQuery()


HTH

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top