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 !
No comments:
Post a Comment