Click here to Skip to main content
Sign Up to vote bad
good
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:21


2 solutions

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  
Comments
hemantwithu - 23 Jan '13 - 0:12
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ő - 23 Jan '13 - 3:04
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.
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 470
1 OriginalGriff 273
2 Dave Kreskowiak 165
3 Mayur_Panchal 154
4 Mohammed Hameed 145
0 Sergey Alexandrovich Kryukov 8,123
1 OriginalGriff 6,173
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid