Please help, I am using a html file field to upload an image to sql server. I keep on getting an error on this line of my code: Error: arithmetic operation resulted in an overflow Dim imgBinaryData As Byte() = New Byte() {imgLen} here is my code: myConnection
= New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim InsertCommand As SqlCommand = New SqlCommand() InsertCommand.Connection = myConnection If Page.IsValid Then Dim imgStream As Stream = BrideImages.PostedFile.InputStream * Dim imgLen
As Integer = BrideImages.PostedFile.ContentLength Dim imgContentType As String = BrideImages.PostedFile.ContentType Dim imgName As String = Trim(txtFileName.Text) * Dim imgBinaryData As Byte() = New Byte() {imgLen} Dim n As Integer = imgStream.Read(imgBinaryData,
0, imgLen) Dim RowsAffected As Integer = SaveToDB(imgName, imgBinaryData, imgContentType) If (RowsAffected > 0) Then Response.Write("
The Image was saved") Else Response.Write("
An error occurred uploading the image") End If End If End Sub Private Function SaveToDB(ByVal imgName As String, ByVal imgbin As Byte(), ByVal imgContentType As String) As Integer myConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim InsertCommand As SqlCommand = New SqlCommand() InsertCommand.Connection = myConnection InsertCommand.CommandText() = "INSERT INTO T_Brides (bFullName, gFullName, Email, Address, City, State, Zip, Phone, Fax, EventDate, imgName, imgData, imgContentType)"
_ & "VALUES ('" & Trim(txtbFullName.Text) & "', '" & Trim(txtGFullName.Text) & "', '" & Trim(txtEmail.Text) & "', " _ & " '" & Trim(txtAddress.Text) & "', '" & Trim(txtCity.Text) & "', '" & Trim(txtState.Text) & "', '" & Trim(txtZip.Text) & "', " _ & " '"
& Trim(txtPhone.Text) & "', '" & Trim(txtFax.Text) & "', '" & Trim(txtEventDate.Text) & "', @imgName, @imgData, @ImgContentType)" Dim param0 As SqlParameter = New SqlParameter("@imgName", SqlDbType.VarChar, 50) param0.Value = imgName InsertCommand.Parameters.Add(param0)
Dim param1 As SqlParameter = New SqlParameter("@imgData", SqlDbType.Image) param1.Value = imgbin InsertCommand.Parameters.Add(param1) Dim param2 As SqlParameter = New SqlParameter("@imgContentType", SqlDbType.VarChar, 50) param2.Value = imgContentType InsertCommand.Parameters.Add(param2)
myConnection.Open() Dim numRowsAffected As Integer = InsertCommand.ExecuteNonQuery() myConnection.Close() Return numRowsAffected End Function
rowens1
Member
10 Points
2 Posts
arithmetic operation resulted in an overflow
Aug 12, 2003 06:18 PM|LINK
The Image was saved") Else Response.Write("
An error occurred uploading the image") End If End If End Sub Private Function SaveToDB(ByVal imgName As String, ByVal imgbin As Byte(), ByVal imgContentType As String) As Integer myConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim InsertCommand As SqlCommand = New SqlCommand() InsertCommand.Connection = myConnection InsertCommand.CommandText() = "INSERT INTO T_Brides (bFullName, gFullName, Email, Address, City, State, Zip, Phone, Fax, EventDate, imgName, imgData, imgContentType)" _ & "VALUES ('" & Trim(txtbFullName.Text) & "', '" & Trim(txtGFullName.Text) & "', '" & Trim(txtEmail.Text) & "', " _ & " '" & Trim(txtAddress.Text) & "', '" & Trim(txtCity.Text) & "', '" & Trim(txtState.Text) & "', '" & Trim(txtZip.Text) & "', " _ & " '" & Trim(txtPhone.Text) & "', '" & Trim(txtFax.Text) & "', '" & Trim(txtEventDate.Text) & "', @imgName, @imgData, @ImgContentType)" Dim param0 As SqlParameter = New SqlParameter("@imgName", SqlDbType.VarChar, 50) param0.Value = imgName InsertCommand.Parameters.Add(param0) Dim param1 As SqlParameter = New SqlParameter("@imgData", SqlDbType.Image) param1.Value = imgbin InsertCommand.Parameters.Add(param1) Dim param2 As SqlParameter = New SqlParameter("@imgContentType", SqlDbType.VarChar, 50) param2.Value = imgContentType InsertCommand.Parameters.Add(param2) myConnection.Open() Dim numRowsAffected As Integer = InsertCommand.ExecuteNonQuery() myConnection.Close() Return numRowsAffected End Function