locked
arithmetic overflow error converting int to data type numeric RRS feed

  • Question

  • HI, I am developing an application with VB.Net as front end and SQL Server 2008 as backend. I have a text box in a windows form. The text box is defined as NumericOnly and maxlength of 6 in properties. Iam trying to save the data in the textbox to a table field in sql server which has been defined as [decimal](5, 2). If I click on the save button, iam getting the following error

    "arithmetic overflow error converting int to data type numeric". Can anybody help? The vb.net code is as below

    objSqlStatement = New StringBuilder
    objSqlStatement.Append("UPDATE [Table_Name] SET ")               
    objSqlStatement.Append("[Field_Name] = " & CDbl(textbox1.Text.Trim) & " ")
    objSqlStatement.Append("WHERE [Group_Id] = " & Group_Id)
    objActivateDB.ExecuteNonQuery(objSqlStatement.ToString)

     

    Tuesday, May 13, 2014 6:12 AM

Answers

All replies

  • Hi, [decimal](5, 2) means that the number can have a precision of 5 digits total, and 2 digits are for the decimal portion. but your text box is defined as maxlength of 6, so [decimal](5, 2) is not enough. please change it. 

    See below link for more information:

    http://msdn.microsoft.com/en-us/library/aa258832%28v=sql.80%29.aspx

    • Marked as answer by Carl Cai Monday, May 19, 2014 9:35 AM
    Tuesday, May 13, 2014 6:23 AM
  • use parameters, your kind of solution has proven to fail in more ways then you can test.

    Look to this sample on our website

    http://www.vb-tips.com/ExtendedSQLParameters.aspx


    Success
    Cor

    • Marked as answer by Carl Cai Monday, May 19, 2014 9:35 AM
    Tuesday, May 13, 2014 6:34 AM
  • This is correct and is borrowed from FORTRAN!!!

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me

    Tuesday, May 13, 2014 12:04 PM
  • This is correct and is borrowed from FORTRAN!!!

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me



    Success
    Cor

    Tuesday, May 13, 2014 3:16 PM
  • :) Fortran was a professional language and typically is run on good processors although it was quite capable of being run by unprofessional developers and jesus it was. I have the original game Adventure which is great but it's real spaghetti and was designed by a man for his son. It's a wonderful game and was the first computer game!

    I just found mine. Although Intel is the current owner DEC was the original author of the Fortran that Intel owns.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me



    Tuesday, May 13, 2014 3:23 PM