1

Original Question:

Why do I get an Arithmetic overflow error converting numeric to data type numeric in ADO.NET code using the Money Data Type when amount is greater than $999,999,99?


Just as the question says... I have a bit of ADO.net code in the data access layer that talks to a Sql Server 2008 database. There is an Amount column in the table that is of data type "Money". The code works fine when inserting a record with an amount < $1,000,000 but throws this error when amount is >= $1,000,000:

"Arithmetic overflow error converting numeric to data type numeric"

I can manually run t-sql against the database updating the amount to a value larger than $1,000,000 so the database can except the amount fine... what is it about the following SqlCommand that causes the error to fire?

        MyCommand.Parameters.Add(New SqlParameter("@Amount", SqlDbType.Money))
        If IsNothing(Amount) Then
            MyCommand.Parameters("@Amount").Value = Convert.DBNull
        Else
            MyCommand.Parameters("@Amount").Value = Amount
        End If
4
  • 1
    That was a really long title..... Commented Dec 16, 2009 at 16:20
  • What data type is the Amount variable? Commented Dec 16, 2009 at 16:28
  • The Amount variable's type = Decimal Commented Dec 16, 2009 at 16:32
  • Please give us the rest of the syntax of the command, or whatever stored procedure it's calling Commented Dec 16, 2009 at 16:37

1 Answer 1

1

If an error occurs calling a stored procedure with a value, but no error occurs when directly updating the table with that same value, then that casts suspition upon the data type of the @Amount parameter. Make sure it is also defined as Money.

Sign up to request clarification or add additional context in comments.

1 Comment

As you pointed out through your question... Amount was a decimal but the sql column was money. Once I converted the value before calling the Stored Procedure it worked perfect: CType(Amount, Data.SqlTypes.SqlMoney). Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.