rodeomount
Programmer
I have written the following code to upload an image to sql server 2000 using a fileupload control on the GUI but I'm getting an error stating "An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. " in reference to the ExecuteNonQuery method. What am I doing wrong?
Public Sub Insert()
Dim objConnection As SqlConnection = New SqlConnection(Session("ConnxString"))
Dim objCommand As SqlCommand
objCommand = New SqlCommand("INSERT INTO dbo.Horses (FoalYear,Price,[Image],Descript,Gender,Type)Values(@FoalYear,@Price,@Image,@Descript,@Gender,@Type)")
objCommand.Connection = objConnection
Dim ds As New DataSet
Dim reader As BinaryReader
Dim liImage As SqlParameter
liImage = New SqlParameter("@inputimage", SqlDbType.Image)
Dim fs As FileStream = New FileStream(flupImage.PostedFile.FileName, FileMode.Open)
reader = New BinaryReader(fs)
'Dim fs As System.IO.FileStream = New System.IO.FileStream(Server.MapPath(flupImage.PostedFile.FileName), System.IO.FileMode.Open)
Dim imagecontent() As Byte
'fs.Read(imagecontent, 0, (Convert.ToInt32(fs.Length.ToString, 10) - 1))
imagecontent = reader.ReadBytes(CType(fs.Length, Integer))
fs.Close()
par1.Value = imagecontent
'Creating an object for the 'PagedDataSource' for holding the data.
objCommand.Parameters.AddWithValue("@FoalYear", txtFoalYear.Text)
objCommand.Parameters.AddWithValue("@Price", txtPrice.Text)
objCommand.Parameters.AddWithValue("@Image", liImage)
objCommand.Parameters.AddWithValue("@Descript", txtDescript.Text)
objCommand.Parameters.AddWithValue("@Gender", cboGender.Text)
objCommand.Parameters.AddWithValue("@Type", "SaleHorse")
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
End Sub
Public Sub Insert()
Dim objConnection As SqlConnection = New SqlConnection(Session("ConnxString"))
Dim objCommand As SqlCommand
objCommand = New SqlCommand("INSERT INTO dbo.Horses (FoalYear,Price,[Image],Descript,Gender,Type)Values(@FoalYear,@Price,@Image,@Descript,@Gender,@Type)")
objCommand.Connection = objConnection
Dim ds As New DataSet
Dim reader As BinaryReader
Dim liImage As SqlParameter
liImage = New SqlParameter("@inputimage", SqlDbType.Image)
Dim fs As FileStream = New FileStream(flupImage.PostedFile.FileName, FileMode.Open)
reader = New BinaryReader(fs)
'Dim fs As System.IO.FileStream = New System.IO.FileStream(Server.MapPath(flupImage.PostedFile.FileName), System.IO.FileMode.Open)
Dim imagecontent() As Byte
'fs.Read(imagecontent, 0, (Convert.ToInt32(fs.Length.ToString, 10) - 1))
imagecontent = reader.ReadBytes(CType(fs.Length, Integer))
fs.Close()
par1.Value = imagecontent
'Creating an object for the 'PagedDataSource' for holding the data.
objCommand.Parameters.AddWithValue("@FoalYear", txtFoalYear.Text)
objCommand.Parameters.AddWithValue("@Price", txtPrice.Text)
objCommand.Parameters.AddWithValue("@Image", liImage)
objCommand.Parameters.AddWithValue("@Descript", txtDescript.Text)
objCommand.Parameters.AddWithValue("@Gender", cboGender.Text)
objCommand.Parameters.AddWithValue("@Type", "SaleHorse")
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
End Sub