Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

 

I've 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.", it's a kinda strange because the input value is ok, i think.

So here's the SP:

           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ão
               DataBase.Conn.Open();

               cmd.ExecuteNonQuery();

               //fecha Conexão
               DataBase.Conn.Close();
           }

 

Any help will be appreciated,

TIA

 

Tiago Teixeira

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...