diff bw null and dbnull
What is the diff bw null and dbnull
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Jun 4, 2015, 11:11 AM
Well,
nullis not an instance of any type. Rather, it is an invalid reference.However,
System.DbNull.Value, is a valid reference to an instance ofSystem.DbNull(System.DbNullis a singleton andSystem.DbNull.Valuegives you a reference to the single instance of that class) that represents nonexistent* values in the database.*We would normally say
null, but I don't want to confound the issue.So, there's a big conceptual difference between the two. The keyword
nullrepresents an invalid reference. The classSystem.DbNullrepresents a nonexistent value in a database field. In general, we should try avoid using the same thing (in this casenull) to represent two very different concepts (in this case an invalid reference versus a nonexistent value in a database field).Keep in mind, this is why a lot of people advocate using the null object pattern in general, which is exactly what
System.DbNullis an example of.Manoj BhoirPosted Jun 4, 2015, 8:37 AM
Well, null is not an instance of any type. Rather, it is an invalid reference.
However, System.DbNull.Value, is a valid reference to an instance of System.DbNull (System.DbNull is a singleton and System.DbNull.Value gives you a reference to the single instance of that class) that represents nonexistent* values in the database.
*We would normally say null, but I don't want to confound the issue.
So, there's a big conceptual difference between the two. The keyword null represents an invalid reference. The class System.DbNull represents a nonexistent value in a database field. In general, we should try avoid using the same thing (in this case null) to represent two very different concepts (in this case an invalid reference versus a nonexistent value in a database field).
Keep in mind, this is why a lot of people advocate using the null object pattern in general, which is exactly what System.DbNull is an example of.
Rajeesh MenothPosted Jun 4, 2015, 8:35 AM