Click here to Skip to main content
11,705,212 members (41,918 online)
Rate this: bad
good
Please Sign up or sign in to vote.
I have faced a problem with the dataset when inserting record into DB.I have a table address in which phno (AllowNulls=False,Defaultvalue='0') and mbno(AllowNulls=True,Defaultvalue='0') .While inserting record into database through dataset when I didn't supply any input to the both columns phno is taking default value('0') and mbno is taking "Null".I suppose both has to take default value when there is no input.

I dont know why this is happening.I have written code like this
SqlConnection con = new SqlConnection(connStr);
DataSet ds = new DataSet();
DataRow dr;
SqlCommand cmd = new SqlCommand("select * from address",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
SqlCommandBuilder cmdBuilder;
da.FillSchema (ds,SchemaType.Source );
da.Fill(ds, "address");
 
dr = ds.Tables["address"].NewRow();
dr["sname"] = "tomy";
dr["fname"] = "peter";
 
ds.Tables["address"].Rows.Add(dr);
 
cmdBuilder = new SqlCommandBuilder(da);
da.Update(ds, "address");
Posted 20-Jan-13 19:43pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here in mob number you are set allownulls true. so if you are not giving any mobile number then it will pass as null from c# to db.so it will accept null value.if you want to set default value then set it into allow nulls is true or you can handle in C3 side by checking if values are null set to 0.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 550
1 OriginalGriff 244
2 ppolymorphe 126
3 CPallini 82
4 F-ES Sitecore 70
0 OriginalGriff 8,988
1 Sergey Alexandrovich Kryukov 8,272
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100