Hi every body
I am trying to insert values using linq to sql through textboxes some of these textboxes may contain null values how to insert null values without exception, for example:
{
tblUser u=new tblUser;
u.Name=txt1.text;
u.Mobile=txt2.text;
db.tblUsers.InsertOnSubmit(u);
db.SubmitChanges();
}
if txt1 or txt2 is empty how to avoid exception and insert the null value?
Jaganathan BantheswaranPosted Oct 17, 2013, 5:00 AM
make you name & mobile fields in DB nullable. As name & mobile are strings, this properties will accepts nulls but if you are using int then you have to change as like int? mobile = 0;
While creating table, it should be something like this,
CREATE TABLE SomeTable
(
a INT NOT NULL --- wont allow null
,b INT NULL --- allows null
) ;