Friday, March 9, 2012

File Upload to SQL in 2.0 VB

Can anyone give me an example of how to Upload a file to SQL in asp.net 2.0 using VB?

Thanks

Randy

The way i do it is with a table of 3 columns:

ImgSize(int)
ImgContentType(nvarchar)
ImgFile(image)

Code:

'Pic is a File Upload Contol

Dim cnn As New SqlConnection(strConn)

Dim imgStream As Stream = Pic.PostedFile.InputStream
Dim imgLen As Integer = Pic.PostedFile.ContentLength
Dim imgContentType As String = Pic.PostedFile.ContentType

Dim imgBinaryData As Byte() = New Byte(imgLen) {}
Dim n As Integer = imgStream.Read(imgBinaryData, 0, imgLen)

You then build your command object and set your parameters with
the value you got above (imgStream, imgLen, imgContentType) and
then execute an non query.

Let me know if you need help reading as well !


|||@.amensi: ei that's the same problem as mine! So that's it, but if you don't me asking, can that also upload a MS word text file? if it doesn't can you please post the source code and where to put it? thanks!

No comments:

Post a Comment