Insert Null Value in Decimal Field

I have a form to insert values in a decimal field for SQL Server 2000

When I leave the textbox blank (to insert null value) in the field, I get an error

“Error converting data type nvarchar to numeric.”

How can I insert null into the decimal field when the textbox value is blank ?

Thanks in advance

Cant you just do the following?:

if (txtDecimalTextBox.Text != "")
//Ur code here
insert into tblName (DecimalColumn) VALUES('0.00');

0.00 is not NULL … I want to insert null value in the table

Also, I have around 30 textboxes … so I will have to write the code 30 times :frowning:

First of all, check if nulls are allowed in that filed,
second, do you want it to be done in C# or sql ?
in C# that’ll be:
(blah-blah-db.table.field.or.storedProcParameter).Value = DBNull.Value;
slq - you have an example above, just replace “0.0” with “NULL”

I’ve got a feeling that the database is expecting decimal but the stored procedure is setup to use nvarchar, ie

SqlCommand.Parameters.Add(new SqlParamter("@decimal", SqlDbType.NvarChar));

As above, make sure the database is setup to allow null values, and when sending your data, if your textbox.length != 0 then send the textbox value otherwise send DBNull.Value;