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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 4, 2015, 4:35 AM EDT
Manoj BhoirRank #599 · 4K reputationPosted Jun 4, 2015, 4:37 AM EDT
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.
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Jun 4, 2015, 7:11 AM EDT
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.