Answered by:

arithmetic overflow error converting int to data type numeric

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

The types you specify should match the database columns. I had to make a guess the Group_id.

It appears that you call some local object that accepts a query string as a parameter. That is just wrong. Maybe that objActivateDB also accepts parameters; I don't know about that. But the important thing is that you should never interpolate values
into the query string, but always use parameters. It makes your code simpler to write, and you are protected against SQL injection.

And also, don't add bracket around your column names - it only makes the code more difficult to read.

As for the error, it appears that you have entered a value > 999.99 in your textbox. Don't do that. It will not fit your database column. But maybe you should change the field to not permit entering of such a value to start with.

The types you specify should match the database columns. I had to make a guess the Group_id.

It appears that you call some local object that accepts a query string as a parameter. That is just wrong. Maybe that objActivateDB also accepts parameters; I don't know about that. But the important thing is that you should never interpolate values
into the query string, but always use parameters. It makes your code simpler to write, and you are protected against SQL injection.

And also, don't add bracket around your column names - it only makes the code more difficult to read.

As for the error, it appears that you have entered a value > 999.99 in your textbox. Don't do that. It will not fit your database column. But maybe you should change the field to not permit entering of such a value to start with.