Click here to Skip to main content
15,074,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends

i have a query which is discussed below. Please give your answers as soon as possible.

I have a table name Unit having columns Unitcode,unitname,Unitstatus,UnitOpeningDate.

In this table I have passed default value in unitstatus(not null) and unitopeningdate(null).

Now I have insert data from windows form. But my dataset does not contains the default value. and it gives some error while inserting the data .

Column 'UnitStatus' does not allow nulls.

My Cs code is :

DataRow dataRow = globalCls.dataSet.Tables["tblUnit"].NewRow();
         //  dataRow["UnitStatus"] = (ddlActive.Text == "Active" ? "Y" : "N");
           dataRow["UnitCode"] = txtCode.Text;
           dataRow["UnitName"] = txtName.Text;
           dataRow["UnitAddress"] = txtAddress.Text;
         //  dataRow["UnitOpeningDate"] = DateTime.Now;

How to solve this problem.
Updated 26-Dec-11 23:35pm
Om Prakash Pant 27-Dec-11 5:35am
"Please give your answers as soon as possible" - Is this a Quiz?

You could try passing it a value for the "UnitStatus" column - it appears to be commented out in your code...
Dear sir,
you can not add table default value on dataset , you should explicitly
mention default value from front end.
Import Namespace Like,

          using System.Data.SqlTypes;

and insert null like (SqlDouble.Null) if field is double and (SqlInt16.Null) if field is int and SqlString.Null if it is varchar in database depending upon datatype.

To add default value to your dataset,You can try this :

DataSet dataset = new DataSet();
     dataset.Tables[0].Columns["Column_Name"].DefaultValue = "default_value";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900