am using a Prepared Statement in C#.
SqlCommand inscommand = new SqlCommand(supInsert, connection);
inscommand.Parameters.Add("@ordQty", SqlDbType.Decimal,18);
inscommand.Prepare();
u = inscommand.ExecuteNonQuery();
The above code throws below Exception:
SqlCommand.Prepare method requires parameters of type 'Decimal' have an explicitly set Precision and Scale.
EDIT: How to avoid this Exception
The following would set a Decimal with Precision 18 and Scale 8 (Decimal (18,8))
SqlCommand insertCommand= new SqlCommand(supInsert, connection);
insertCommand.Parameters.Add("@ordQty", SqlDbType.Decimal,18);
insertCommand.Parameters["@ordQty"].Precision = 18;
insertCommand.Parameters["@ordQty"].Scale = 8;
insertCommand.Prepare();
u = insertCommand.ExecuteNonQuery();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With