Uploading Blobs

daganlev

Member
Joined
Sep 20, 2006
Messages
5
Programming Experience
Beginner
Hi ppl,
I hope this is the right place to ask...

I have created an update feature on my vb.net app that loads images from a server, it gets the picture as a stream from the server and than suppose to update it to the DB (MS-Access)

Here is the code:

VB.NET:
Dim html2 AsNew WebClient()
'reads the picture off the internet stream
Dim data2 As Stream = html2.OpenRead(txtURL.Text & "?id=" & id)
 
 
Dim cmd3 AsNew OleDb.OleDbCommand("insert into pics(data) values(?)", con2)
Dim data AsNew SqlClient.SqlParameter("@data", data2)
data.Direction = ParameterDirection.Input
cmd3.Parameters.Add(Image.FromStream(data))
cmd3.ExecuteNonQuery()
This does not seem to work, I had put the result of the stream into a picturebox on the form i.e.
Picturebox1.Image = Image.FromStream(data)

and it did come out...

what am i doing wrong??? please help???
 
Last edited by a moderator:
The code there seems a bit wrong really:

VB.NET:
Dim data2 As Stream = html2.OpenRead(txtURL.Text & "?id=" & id)
Dim data AsNew SqlClient.SqlParameter("@data", data2)
So what youre doing is trying to insert a Stream directly into the DB - which really isnt going to work.

I think you will need to read from the WebClient stream a byte at a time, into a Byte() array - and then insert that into the database.

Sorry I dont have time to write any code and test it, if I get a chance this afternoon ill post again - maybe this is enough to point you in the right direction?
 
Last edited by a moderator:
Back
Top