Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MS-Access
Is null is acceptable for the number Column having Default value '0'?Can any one explain clearly?
Posted 21-Jan-13 2:21am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Having a field nullable has nothing to do whit it's type or default value. It is a separate property of the field. So you either make it nullable or not-nullable - thus it will accept accept or reject null values, independent of type and default value.
Having the default value set, means that it will use that value if the field is omitted on insert, but not if there is a null. See following example.
Let's suppose you have a table T with two numeric fields: D1 nullable-default 0, D2 not nullable. Now if you issue following statements:
insert into T(D1, D2) values(100,200) you will get 100,200
insert into T(D1, D2) values(null,100) you will get null,100
insert into T(D2) values(200) you will get 0,200 and there you see the default value.
  Permalink  
v2
Comments
hemantwithu at 23-Jan-13 0:12am
   
But Here I am not inserting the record with direct insert query as "insert into table values(@c1,@c2)".I am inserting record using DataSet as 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");
Zoltán Zörgő at 23-Jan-13 3:04am
   
The provider is working a little bit different: it won't take such properties from the schema! You use a select statement as source. The FillSchema won't have idea how to get the metadata from the original table.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Null and 0 are two different values.
Null indicates nothing was present and 0 indicates a value.
 
Thus, IMO, null and 0 are not the same and one cannot be replaced with the other.
 
Have a look at nullable types[^] for an integer.
  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 9,108
1 OriginalGriff 8,186
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,928


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