Hi group,

It's been some time since I last posted. It's good to be involved in programming again. It's been much too long.

It's been a while since I've written code that would write to a SQL database. It seems like the connection string is correct. However I'm getting a 'InvalidArithmetic operation resulted in an overflow'. I'm unsure why I'm getting this. Hopefully one of you will see it in my code and make a suggestion on how to fix. Here's my code:

    Dim con As New SqlConnection
    Dim cmd As New SqlCommand
    Dim query As String = "INSERT INTO CustRec (CustAccntNo, CustName, CustAddr1, CustAddr2, CustCity, CustState, CustZipCode, CustPhoneNo, CustAltPhone, CustType, CustSendStatement, CustCreateDate) &
             VALUES (@AcctNo, @CustName, @Addr1, @Addr2, @City, @State, @ZipCode, @Phone, @AltPhone, @CustType, @SendStatement, @CreateDate) "
        con.ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=C:\USERS\DON\DOCUMENTS\SALES.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
        cmd.Connection = con
        cmd = New SqlCommand((query), con)
        cmd.Parameters.Add("@AcctNo", SqlDbType.Int).Value = CInt(tbxAccntNo.Text)
        cmd.Parameters.Add("@CustName", SqlDbType.VarChar).Value = tbxCustomerName.Text
        cmd.Parameters.Add("@Addr1", SqlDbType.VarChar).Value = tbxAddr1.Text
        cmd.Parameters.Add("@Addr2", SqlDbType.VarChar).Value = tbxAddr2.Text
        cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = tbxCity.Text
        cmd.Parameters.Add("@State", SqlDbType.VarChar).Value = tbxState.Text
        cmd.Parameters.Add("@ZipCode", SqlDbType.VarChar).Value = tbxZipCode.Text
        cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = tbxCustPhoneNo.Text
        cmd.Parameters.Add("@AltPhone", SqlDbType.VarChar).Value = tbxCustAltPhone.Text
        cmd.Parameters.Add("@CustType", SqlDbType.VarChar).Value = tbxCustType.Text
        cmd.Parameters.Add("@SendStatement", SqlDbType.VarChar).Value = tbxSendStatement.Text
        cmd.Parameters.Add("@CreateDate", SqlDbType.Date).Value = Date.Now

    Catch ex As Exception
        MessageBox.Show("Invalid" & ex.Message)
    End Try

Do you see where it may be? The only thing 'arithmetic' is that I'm converting a number in a textbox to Cint because it is an integer (a 7 digit integer ie. 9999999999). Any thoughts?

Thanks for your help


That's 10 digits, not 7 and as such can hold values > 2^31 which cannot be stored in an int.

(Although I have no idea if that is actually the problem. Just sayin')

commented: I see the issue now. The int data type can store whole numbers from -2147483648 to 2147483647. +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.