Arithmetic overflow error converting numeric to data type numeric.

teixeira

Well-known member
Joined
Apr 5, 2005
Messages
94
Location
LEIRIA-PORTUGAL
Hi

Ive a table in my SQL SERVER 2005 Express database with a couple of columns with decimal(4,2) data type, but when i try to insert a value on it, using the following stored procedure, i get this error: "Arithmetic overflow error converting numeric to data type numeric.", its a kinda strange because the input value is ok, i think.
So heres the SP:
Code:
            using (SqlCommand cmd = new SqlCommand())
            {
                decimal qt = decimal.parse(qttTextBox.Text);
                cmd.Connection = DataBase.Conn;//Cria connection se n existir automaticamente
                cmd.CommandText = "spCriarLinhasPrescricao";
                cmd.CommandType = CommandType.StoredProcedure;

                //Parametros SP
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@idMedicamento", SqlDbType.Int).Value = medicamentoId;
                cmd.Parameters.Add("@idPaciente", SqlDbType.Int).Value = pacienteId;
                cmd.Parameters.Add("@quant", SqlDbType.Decimal).Value = qt; //Here comes the error

                //Abre Conex
 
Solved!
Decimal(4,2) does not alows a value greater that 99.99 but decimal(6,2) solves my issue and i can then store 9999.99

regards,
Tiago Teixeira
 
You may also want to investigate the "money" type. Decimal should work fine, but be careful to not make it too small - as you found out :)

-ner
 
Back
Top