0

Hello,
I have this error "Arithmetic operation resulted in an overflow." I have no mathematical operations in my code. Why would that error come up?
This is code:

Public Sub Check_Record()
         Try
        SQLCon.ConnectionString = "Data Source=10.138.26.38; Initial Catalog = Safety_Database; User ID=sa; Password=spd"
        SQLCon.Open()
        'change the data fields names and table according to your database
        SQLCmd.CommandText = " SELECT * FROM  Employee_Information  WHERE (FileNumber = '" & SafetyDatabase.txtFileNumber.Text & "')"
        SQLCmd.Connection = SQLCon

      Dim lrd As SqlDataReader = SQLCmd.ExecuteReader()
        If lrd.HasRows Then
            SQLCon.Close()
            SafetyDatabase.UpdateRecord()
        Else
            SQLCon.Close()
            SafetyDatabase.CreateRecord()
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub

This is the Save button that is calling the code from the Check_Record.

 Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
       Check_Record()
End Sub

This is the Update and Create methods:

        Public Sub UpdateRecord()
            Try
               Dim cn As New SqlConnection
            cn.ConnectionString = "Data Source=10.138.26.38;Initial Catalog=Safety_Database;User ID=sa;Password=spd"
        cn.Open()
        cmd.Connection = cn

        cmd.CommandText = "UPDATE Employee_Information SET EmployeeFirstName = '" & txtFirstName.Text & "', Middle_Initial= '" & txtMiddle.Text & "', EmployeeLastName = '" & txtLastName.Text & "', Suffix= '" & txtSuffix.Text & "', Phone= '" & txtHome.Text & "', Mobile_Phone= '" & txtMobile.Text & "', Department= '" & txtDepartment.Text & "', Gender= '" & txtGender.Text & "', QRCI= '" & txtQRCI.Text & "', Employee_Address = '" & txtEmployeeAddress.Text & "', Employee_City= '" & txtCity.Text & "', Employee_Zip='" & txtZipCode.Text & "', Employee_APT='" & txtAPT.Text & "', DOB='" & txtEmployeeDOB.Text & "', Date_of_Incident='" & txtDateIncident.Text & "', Time_of_Incident= '" & txtTimeIncident.Text & "', Date_of_Report= '" & txtDateReport.Text & "', Dept= '" & cbDept.Text & "', OP_Station= '" & cbOPNumber.Text & "', Shift= '" & cbShift.SelectedItem.ToString & "', Clinic_Radio_Yes= '" & rbClinicYes.Text & "', Clinic_Radio_No= '" & rbClinicNo.Text & "', Sent_to_ClinicName= '" & cbClinicName.Text & "', Clinic_Radio_Yes= '" & rbClinicYes.Text & "', Clinic_Radio_No= '" & rbClinicNo.Text & "', Supervisor_First_Name= '" & txtSupervisorFirstName.Text & "', Supervisor_Last_Name= '" & txtSupervisorLastName.Text & "', Machine_Radio_Yes= '" & rbMachineYes.Text & "', Machine_Radio_No= '" & rbMachineNo.Text & "', Machine_Equipment_Description= '" & txtMEDescription.Text & "', Injury_Illness= '" & txtInjury.Text & "', Part_of_Body= '" & txtPartofBody.Text & "', Location_of_Body= '" & txtLocationofBody.Text & "', Type_of_Incident= '" & txtTypeofIncident.Text & "', Property_Radio_Yes= '" & rbYes.Text & "', Property_Radio_No= '" & rbNo.Text & "', Property_Damage_Description= '" & txtPropertyDamageDescription.Text & "', Property_Radio_Yes= '" & Proper_PPE_Yes.Text & "', Property_Radio_No= '" & Proper_PPE_No.Text & "' PPE_SWI= '" & cbGloves.SelectedItem.ToString & "', Incident_Occurance= '" & txtOccur.Text & "', Accident_Occurance= '" & txtSubstance.Text & "', Nature_of_Injury= '" & txtDescriptionInjury.Text & "', Substance_Harmed= '" & txtSubstance.Text & "', Witness= '" & txtWitnesses.Text & "', Employee_Signature= '" & txtEmployeeSignatureature.Text & "', EmployeeDate= '" & txtEmployeeDate.Text & "', Equipment= '" & SafetyDatabase2.clbEquipment.SelectedItem.ToString & "', Environment= '" & SafetyDatabase2.clbEnvironment.Text & "', People= '" & SafetyDatabase2.clbPeople.Text & "', ManagementSystem= '" & SafetyDatabase2.clbMangementSystem.Text & "', Explain= '" & SafetyDatabase2.txtExplain.Text & "', CAEquipment= '" & SafetyDatabase2.clbCAEquip.Text & "', CAEnvironment= '" & SafetyDatabase2.clbCAEnvironment.Text & "', CAPeople= '" & SafetyDatabase2.clbCAPeople.Text & "', CAManagementSystem= '" & SafetyDatabase2.clbCAManagmentSystem.Text & "', Corrective_Action_PPE= '" & SafetyDatabase2.clbCAPPE.Text & "', FullyDetailAction_Action= '" & SafetyDatabase2.txtFullDetailAction.Text & "', FullyDetailAction_Action2= '" & SafetyDatabase2.txtFullDetailAction2.Text & "', FullyDetailAction_Action3= '" & SafetyDatabase2.txtFullDetailAction3.Text & "', FullyDetailAction_Action4= '" & SafetyDatabase2.txtFullDetailAction4.Text & "', FullyDetailAction_Action5= '" & SafetyDatabase2.txtFullDetailAction5.Text & "', FullyDetailAction_Responsibilty= '" & SafetyDatabase2.txtFullDetailAction_Responsiblity.Text & "', FullyDetailAction_Responsibilty2= '" & SafetyDatabase2.txtFullDetailAction_Responsiblity2.Text & "', FullyDetailAction_Responsibilty3= '" & SafetyDatabase2.txtFullDetailAction_Responsiblity3.Text & "', FullyDetailAction_Responsibilty4= '" & SafetyDatabase2.txtFullDetailAction_Responsiblity4.Text & "', FullyDetailAction_Responsibilty5= '" & SafetyDatabase2.txtFullDetailAction_Responsiblity5.Text & "', FullyDetailAction_TargetCompletionDate= '" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate.Text & "', FullyDetailAction_TargetCompletionDate2= '" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate2.Text & "', FullyDetailAction_TargetCompletionDate3= '" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate3.Text & "', FullyDetailAction_TargetCompletionDate4= '" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate4.Text & "', FullyDetailAction_TargetCompletionDate5= '" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate5.Text & "', Completed_Date= '" & SafetyDatabase2.cbCompleted1.Text & "', Completed_Date2= '" & SafetyDatabase2.cbCompleted2.Text & "', Completed_Date3= '" & SafetyDatabase2.cbCompleted3.Text & "', Completed_Date4= '" & SafetyDatabase2.cbCompleted4.Text & "', Completed_Date5= '" & SafetyDatabase2.cbCompleted5.Text & "', Completed_DateCB= '" & SafetyDatabase2.txtCompletedDate1.Text & "', Completed_DateCB2= '" & SafetyDatabase2.txtCompletedDate2.Text & "', Completed_DateCB3= '" & SafetyDatabase2.cbCompleted3.Text & "', Completed_DateCB4= '" & SafetyDatabase2.cbCompleted4.Text & "', Completed_DateCB5= '" & SafetyDatabase2.cbCompleted5.Text & "' ImmediateSupervisor= '" & SafetyDatabase2.txtImmediateSupervisor_Print.Text & "', ImmediateSupervisor_Date= '" & SafetyDatabase2.dateImmediateSupervisor.Text & "', NextlevelSupervisor= '" & SafetyDatabase2.txtNextLevelManager_Print.Text & "', NextlevelSupervisor_Date= '" & SafetyDatabase2.dateNextLevelManager.Text & "', HR_SafetyRepresentative= '" & SafetyDatabase2.txtHRSafetyRep_Print.Text & "', HR_SafetyRepresentative_date= '" & SafetyDatabase2.dateHRSafetyRep.Text & "', Employee_ID= '" & txtEmpID.Text & "', FileNumber= '" & txtFileNumber.Text & "', DateTime= '" & DateTime.Text & "', Job_Title= '" & txtJobTitle.Text & "', Hire_Date= '" & txtDateofHire.Text & "' WHERE (FileName= '" & txtFileNumber.Text & "')"
        cmd.ExecuteNonQuery()
        MessageBox.Show("Record Added/Updated")

     Catch ex As Exception
        MessageBox.Show("Error while inserting record on table..." & ex.Message, "Update Records")
    Finally
        cn.Close()
    End Try
End Sub

Create Method

    Public Sub CreateRecord()
    Try
        Dim cn As New SqlConnection
        cn.ConnectionString = "Data Source=10.138.26.38;Initial Catalog=Safety_Database;User ID=sa;Password=spd"

        cn.Open()

        cmd.CommandText = "INSERT INTO Employee_Information (EmployeeFirstName, Middle_Initial, EmployeeLastName, Suffix, Phone, Mobile_Phone, Department, QRCI, DOB, Gender, Employee_Address, Employee_City, Employee_State, Employee_Zip, Employee_Apt, Date_of_Incident, Time_of_Incident, Date_of_Report, Dept, OP_Station, Shift, Clinic_Radio_Yes, Clinic_Radio_No, Sent_to_ClinicName, Supervisor_First_Name, Supervisor_Last_Name, Machine_Radio_Yes, Machine_Radio_No, Machine_Equipment_Description, Injury_Illness, Part_of_Body, Location_of_Body, Type_of_Incident, Property_Radio_Yes, Property_Radio_No, Property_Damage_Description, PPE_Yes, PPE_No, PPE_SWI, Incident_Occurence, Accident_Occurence, Nature_of_Injury, Substance_Harmed, Witness, Employee_Signature_Print, Employee_Signature, EmployeeDate,Equipment, Environment, People, ManagementSystem, Explain, CAEquipment, CAEnvironment, CAPeople, CAManagementSystem, Corrective_Action_PPE, FullyDetailAction_Action, FullyDetailAction_Action2, FullyDetailAction_Action3, FullyDetailAction_Action4, FullyDetailAction_Action5, FullyDetailAction_Responsibilty, FullyDetailAction_Responsibilty2, FullyDetailAction_Responsibilty3, FullyDetailAction_Responsibilty4, FullyDetailAction_Responsibilty5, FullyDetailAction_TargetCompletionDate, FullyDetailAction_TargetCompletionDate2, FullyDetailAction_TargetCompletionDate3, FullyDetailAction_TargetCompletionDate4, FullyDetailAction_TargetCompletionDate5, Completed_Date, Completed_Date2, Completed_Date3, Completed_Date4, Completed_Date5, Completed_DateCB, Completed_DateCB2, Completed_DateCB3, Completed_DateCB4, Completed_DateCB5, ImmediateSupervisor, ImmediateSupervisor_Date, NextlevelSupervisor, NextlevelSupervisor_Date, HR_SafetyRepresentative, HR_SafetyRepresentative_date, Employee_ID, FileNumber, DateTime, Job_Title, Hire_Date) VALUES('" & txtFirstName.Text & "','" & txtMiddle.Text & "','" & txtLastName.Text & "','" & txtSuffix.Text & "','" & CInt(rawPhoneNumber) & "','" & CInt(rawPhoneNumber1) & "','" & txtDepartment.Text & "','" & txtQRCI.Text & "','" & txtEmployeeDOB.Text & "','" & txtGender.Text & "','" & txtEmployeeAddress.Text & "','" & txtCity.Text & "','" & cbState.Text & "','" & txtZipCode.Text & "','" & txtAPT.Text & "','" & txtDateIncident.Text & "','" & txtTimeIncident.Text & "','" & txtDateReport.Text & "','" & cbDept.Text & "','" & cbOPNumber.Text & "','" & cbShift.Text & "','" & rbClinicYes.Text & "','" & rbClinicNo.Text & "','" & cbClinicName.SelectedItem.ToString & "','" & txtSupervisorFirstName.Text & "','" & txtSupervisorLastName.Text & "','" & rbMachineYes.Text & "','" & rbMachineNo.Text & "','" & txtMEDescription.Text & "','" & txtInjury.Text & "','" & txtPartofBody.Text & "','" & txtLocationofBody.Text & "','" & txtTypeofIncident.Text & "','" & rbYes.Text & "','" & rbNo.Text & "','" & txtPropertyDamageDescription.Text & "','" & cbGloves.Text & "','" & Proper_PPE_Yes.Text & "','" & Proper_PPE_No.Text & "','" & txtOccur.Text & "','" & txtAccidentOccurance.Text & "','" & txtDescriptionInjury.Text & "','" & txtSubstance.Text & "','" & txtWitnesses.Text & "', '" & txtEmployeeSign.Text & "','" & txtEmployeeSignatureature.Text & "','" & txtEmployeeDate.Text & "','" & SafetyDatabase2.clbEquipment.SelectedItem.ToString & "','" & SafetyDatabase2.clbEnvironment.SelectedItem.ToString & "','" & SafetyDatabase2.clbPeople.SelectedItem.ToString & "','" & SafetyDatabase2.clbMangementSystem.SelectedItem.ToString & "','" & SafetyDatabase2.txtExplain.Text & "','" & SafetyDatabase2.clbCAEquip.Text & "','" & SafetyDatabase2.clbCAEnvironment.SelectedItem.ToString & "','" & SafetyDatabase2.clbCAPeople.SelectedItem.ToString & "','" & SafetyDatabase2.clbCAManagmentSystem.SelectedItem.SelectedItem.ToString & "','" & SafetyDatabase2.clbCAPPE.SelectedItem.ToString & "','" & SafetyDatabase2.txtFullDetailAction.Text & "','" & SafetyDatabase2.txtFullDetailAction2.Text & "','" & SafetyDatabase2.txtFullDetailAction3.Text & "','" & SafetyDatabase2.txtFullDetailAction4.Text & "','" & SafetyDatabase2.txtFullDetailAction5.Text & "','" & SafetyDatabase2.txtFullDetailAction_Responsiblity.Text & "','" & SafetyDatabase2.txtFullDetailAction_Responsiblity2.Text & "','" & SafetyDatabase2.txtFullDetailAction_Responsiblity3.Text & "','" & SafetyDatabase2.txtFullDetailAction_Responsiblity4.Text & "','" & SafetyDatabase2.txtFullDetailAction_Responsiblity5.Text & "','" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate.Text & "','" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate2.Text & "','" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate3.Text & "','" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate4.Text & "','" & SafetyDatabase2.txtFullDetailAction_TargetCompleteDate5.Text & "','" & SafetyDatabase2.cbCompleted1.Text & "','" & SafetyDatabase2.cbCompleted2.Text & "','" & SafetyDatabase2.cbCompleted3.Text & "','" & SafetyDatabase2.cbCompleted4.Text & "','" & SafetyDatabase2.cbCompleted5.Text & "','" & SafetyDatabase2.txtCompletedDate1.Text & "','" & SafetyDatabase2.txtCompletedDate2.Text & "','" & SafetyDatabase2.txtCompletedDate3.Text & "','" & SafetyDatabase2.txtCompletedDate4.Text & "','" & SafetyDatabase2.txtCompletedDate5.Text & "','" & SafetyDatabase2.txtImmediateSupervisor_Print.Text & "','" & SafetyDatabase2.dateImmediateSupervisor.Text & "','" & SafetyDatabase2.txtNextLevelManager_Print.Text & "','" & SafetyDatabase2.dateNextLevelManager.Text & "','" & SafetyDatabase2.txtHRSafetyRep_Print.Text & "','" & SafetyDatabase2.dateHRSafetyRep.Text & "','" & txtEmpID.Text & "','" & txtFileNumber.Text & "','" & DateTime.Text & "','" & txtJobTitle.Text & "','" & txtDateofHire.Text & "')"
        cmd.Connection = cn

        cmd.ExecuteNonQuery()
        MessageBox.Show("Record Added/Updated")

    Catch ex As Exception
        MessageBox.Show(ex.Message)
        'MessageBox.Show("Error While Inserting record Into Table" & ex.Message, "Insert Records")
    Finally
        cn.Close()
    End Try
End Sub

Edited by Ammar_8

2
Contributors
2
Replies
18
Views
5 Months
Discussion Span
Last Post by chriswelborn
0

The Save Button is suppose to determine whether the information entered in the application has already assigned a file number or not. If the application has been assigned a file number, then application should update the records. If else the application would create a new record.
Once clicked on the Save Button, the application throws out this error, Arithmetic operation resulted in an overflow.

1

It's been a while since I messed with VB, but I can't find anything that sticks out as far as the overflow situation. It's hard to read anything the way you're building those queries. I'm pretty sure that they're prone to SQL injection anyway. Have you looked at prepared statements? So the user can't just enter 2016-22-13'); DROP TABLE Employee_Information; into txtDateOfHire?

Can you print some kind of stack trace, showing exactly where the error takes place?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.