VB.Net used to add files to SQL Server
Date: 05/09/06
(Asp Dot Net) Keywords: database, asp, sql, web
Christ I post so much to this group that its like if I keep doing it I'm automatically entered in a raffle..
Anyways I have a ASP.Net/VB.net webform that allows a user to upload a file into a SQL Server database. I can't figure out how to get the file to be inserted correctly though. We have to use a data access class, but I can modify it to my needs. I also need to pass this to a stored procedure on the database, as opposed to using commands in the vb code.
This is how I get the file:
Dim strFileName As String = _
fileupload1.PostedFile.FileName.Substring _
(fileupload1.PostedFile.FileName.LastIndexOf("\") + 1)
Dim fileLength As Integer = CInt(fileupload1.PostedFile.ContentLength)
Dim fileContent(fileLength) As Byte
fileupload1.PostedFile.InputStream.Read(fileContent, 0, fileLength)
I keep getting all sort of casting errors and other crap when I try and pass this through my stored procedure. I don't think my error lies in there, because it looks like its not being "converted" to the proper format or it just isn't going over properly. I can't seem to find any tangible "good" info online about this. Can anyone help out? Thanks.
Source: http://community.livejournal.com/aspdotnet/65161.html