Click here to Skip to main content
13,550,215 members
Rate this:
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";


cmdBuilder = new SqlCommandBuilder(da);
da.Update(ds, "address");
Posted 20-Jan-13 19:43pm

1 solution

Rate this: bad
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 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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180515.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2018
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