SlideShare a Scribd company logo
1 of 3
Download to read offline
Difference between null and System.DBNull.Value

      S.No     null                                DBNull


      1        Conceptual Difference:              Conceptual Difference:
               The keyword null represents         The class System.DbNull
               an invalid reference.               represents a nonexistent value in a
                                                   database field.

      2        What is the purpose of null         What is the purpose of DBNull
               keyword ?                           class ?
               NULL is used to check if a          DBNULL is used to check if a
               whole record is not found in        certain field in a database is null.
               the database.

      3        Is it a Value / Reference /         Is it a Value / Reference /
               Nullable type ?                     Nullable type ?
               null is the default value of        DBNull does not match the type of
               reference-type variables.           a nullable value type, a reference
               Ordinary value types cannot be      type, or a value type, and therefore
               null.                               is not directly assignable.

                                                   Please look at: Handle null, then
                                                   DBNull to avoid
                                                   InvalidCastException

                                                   Reason:
                                                   Of DBNull class only one instance
                                                   can exist as it a singleton class.
                                                   Sole instance is DBNull.Value.

Handle null, then DBNull to avoid InvalidCastException:

For instance, sometimes in code you will see items in a data row being used without
checking for null first. When the underlying field is not null, this is OK, but if a null is
available, the following code will not work:

Example-1

Decimal amount = (Decimal)row["AmountValue"]; //returned value is DBNull

Because DBNull is not the same type, an InvalidCastException occurs. Rather, a null
check has to be performed. The safe alternative to this is the following:

Example-2

Decimal amount = 0;
If (!row.IsNull("AmountValue"))
  amount = (Decimal)row["AmountValue"];

If you want to set a row's value, you can do something like below. The row takes an
instance of type object, and therefore can be assigned DBNull:

Example-3

If (amountValue > 0)
  row["AmountValue"] = amountValue;
Else
  row["AmountValue"] = DBNull.Value;

The value property returns the actual instance of DBNull (a static property). Sometimes, a
helper routine would be good to handle this conversion for you, reducing the amount to a
total of one line instead of four. That may not seem like much, but a table with thirty
columns will make this much coding a chore.

Checking null and DBNull values

How to check for null value ?

   1. Create the variable. A variable must be declared before using it. The code below
allocates memory and declares the variable for use.
   string myNullVar = null;
   The code uses the "null" value assignment for the new variable.
   2. Check if the variable is null. The code below checks if the variable is null. If it is null,
the code assigns it a color value.
   if(myNullVar == null) {
   myNullVar = "purple";
   }

   3.Check if the variable is not null. In some cases, you may wan to reassign the variable
back to null. The following code checks if the variable is not null, and assigns it a null
value.
  if(myNullVar != null) {
  myNullVar = null;
  }

How to check for DBNull values ?

   4. Declare a variable. Just like section 1, to check for DBNull, a variable needs to be
declared. However, the variable is assigned the DBNull value.
   string myNullVar = System.DBNull;
   5. Use the "Equals()" method from the string class to check for the DBNull value. The
code below checks for this value and assigns myNullVar a color.
   if (myNullVar.Equals(System.DBNull.Value)) {
   myNullVar = "purple";
   }
   6.Evaluate if the variable is not null. Similar to section one, you may want to check if the
variable is not null to reassign it back to DBNull. The "!" character evaluates to "not" in the
following example.
   if(!myNullValue.Equals(System.DBNull.Value)) {
   myNullValue = System.DBNull;
   }
Note:
 However note that neither checking null of nor DBNull.value will work if the index is out of
range. If we check for an index or a column that doesn't exist, it will throw an index out of
range exception.

References:
http://stackoverflow.com/questions/4958379/what-is-the-difference-between-null-and-
system-dbnull-value

http://www.dotnetspider.com/forum/315649-Difference-between-NULL-DBNULL.aspx

http://aspalliance.com/1460_More_InDepth_About_Nulls_And_DBNull.4

http://msdn.microsoft.com/en-us/library/system.dbnull.value.aspx

http://msdn.microsoft.com/en-us/library/edakx9da.aspx

http://www.ehow.com/how_5158769_check-null-value-c.html

http://dotnetanalysis.blogspot.in/2012/07/c-difference-between-dbnullvalue-and.html

And, further updates on difference between questions and answers, please visit my
blog @ http://onlydifferencefaqs.blogspot.in/

More Related Content

Viewers also liked

Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012Umar Ali
 
Asset Management Abstract
Asset Management AbstractAsset Management Abstract
Asset Management Abstractatavane
 
Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questionsUmar Ali
 

Viewers also liked (6)

Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012
 
Higiene en la adolecencia mujeres
Higiene en la adolecencia mujeresHigiene en la adolecencia mujeres
Higiene en la adolecencia mujeres
 
Asset Management Abstract
Asset Management AbstractAsset Management Abstract
Asset Management Abstract
 
Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questions
 
Motivation theory
Motivation theoryMotivation theory
Motivation theory
 
Break Even Analysis
Break Even AnalysisBreak Even Analysis
Break Even Analysis
 

More from Umar Ali

Difference between wcf and asp.net web api
Difference between wcf and asp.net web apiDifference between wcf and asp.net web api
Difference between wcf and asp.net web apiUmar Ali
 
Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Umar Ali
 
Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Umar Ali
 
Difference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcDifference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcUmar Ali
 
Difference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcDifference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcUmar Ali
 
ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1Umar Ali
 
Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1Umar Ali
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1Umar Ali
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1Umar Ali
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1 Umar Ali
 
How to create user friendly file hosting link sites
How to create user friendly file hosting link sitesHow to create user friendly file hosting link sites
How to create user friendly file hosting link sitesUmar Ali
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamilUmar Ali
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamilUmar Ali
 
Asp.net website usage and job trends
Asp.net website usage and job trendsAsp.net website usage and job trends
Asp.net website usage and job trendsUmar Ali
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1 Umar Ali
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1 Umar Ali
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search enginesUmar Ali
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1Umar Ali
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1Umar Ali
 
.NET Differences List
.NET Differences List.NET Differences List
.NET Differences ListUmar Ali
 

More from Umar Ali (20)

Difference between wcf and asp.net web api
Difference between wcf and asp.net web apiDifference between wcf and asp.net web api
Difference between wcf and asp.net web api
 
Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()
 
Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4
 
Difference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcDifference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvc
 
Difference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcDifference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvc
 
ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1
 
Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1
 
How to create user friendly file hosting link sites
How to create user friendly file hosting link sitesHow to create user friendly file hosting link sites
How to create user friendly file hosting link sites
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamil
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamil
 
Asp.net website usage and job trends
Asp.net website usage and job trendsAsp.net website usage and job trends
Asp.net website usage and job trends
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search engines
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1
 
.NET Differences List
.NET Differences List.NET Differences List
.NET Differences List
 

Recently uploaded

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Difference between null and system.db null.value

  • 1. Difference between null and System.DBNull.Value S.No null DBNull 1 Conceptual Difference: Conceptual Difference: The keyword null represents The class System.DbNull an invalid reference. represents a nonexistent value in a database field. 2 What is the purpose of null What is the purpose of DBNull keyword ? class ? NULL is used to check if a DBNULL is used to check if a whole record is not found in certain field in a database is null. the database. 3 Is it a Value / Reference / Is it a Value / Reference / Nullable type ? Nullable type ? null is the default value of DBNull does not match the type of reference-type variables. a nullable value type, a reference Ordinary value types cannot be type, or a value type, and therefore null. is not directly assignable. Please look at: Handle null, then DBNull to avoid InvalidCastException Reason: Of DBNull class only one instance can exist as it a singleton class. Sole instance is DBNull.Value. Handle null, then DBNull to avoid InvalidCastException: For instance, sometimes in code you will see items in a data row being used without checking for null first. When the underlying field is not null, this is OK, but if a null is available, the following code will not work: Example-1 Decimal amount = (Decimal)row["AmountValue"]; //returned value is DBNull Because DBNull is not the same type, an InvalidCastException occurs. Rather, a null check has to be performed. The safe alternative to this is the following: Example-2 Decimal amount = 0; If (!row.IsNull("AmountValue")) amount = (Decimal)row["AmountValue"]; If you want to set a row's value, you can do something like below. The row takes an
  • 2. instance of type object, and therefore can be assigned DBNull: Example-3 If (amountValue > 0) row["AmountValue"] = amountValue; Else row["AmountValue"] = DBNull.Value; The value property returns the actual instance of DBNull (a static property). Sometimes, a helper routine would be good to handle this conversion for you, reducing the amount to a total of one line instead of four. That may not seem like much, but a table with thirty columns will make this much coding a chore. Checking null and DBNull values How to check for null value ? 1. Create the variable. A variable must be declared before using it. The code below allocates memory and declares the variable for use. string myNullVar = null; The code uses the "null" value assignment for the new variable. 2. Check if the variable is null. The code below checks if the variable is null. If it is null, the code assigns it a color value. if(myNullVar == null) { myNullVar = "purple"; } 3.Check if the variable is not null. In some cases, you may wan to reassign the variable back to null. The following code checks if the variable is not null, and assigns it a null value. if(myNullVar != null) { myNullVar = null; } How to check for DBNull values ? 4. Declare a variable. Just like section 1, to check for DBNull, a variable needs to be declared. However, the variable is assigned the DBNull value. string myNullVar = System.DBNull; 5. Use the "Equals()" method from the string class to check for the DBNull value. The code below checks for this value and assigns myNullVar a color. if (myNullVar.Equals(System.DBNull.Value)) { myNullVar = "purple"; } 6.Evaluate if the variable is not null. Similar to section one, you may want to check if the variable is not null to reassign it back to DBNull. The "!" character evaluates to "not" in the following example. if(!myNullValue.Equals(System.DBNull.Value)) { myNullValue = System.DBNull; }
  • 3. Note: However note that neither checking null of nor DBNull.value will work if the index is out of range. If we check for an index or a column that doesn't exist, it will throw an index out of range exception. References: http://stackoverflow.com/questions/4958379/what-is-the-difference-between-null-and- system-dbnull-value http://www.dotnetspider.com/forum/315649-Difference-between-NULL-DBNULL.aspx http://aspalliance.com/1460_More_InDepth_About_Nulls_And_DBNull.4 http://msdn.microsoft.com/en-us/library/system.dbnull.value.aspx http://msdn.microsoft.com/en-us/library/edakx9da.aspx http://www.ehow.com/how_5158769_check-null-value-c.html http://dotnetanalysis.blogspot.in/2012/07/c-difference-between-dbnullvalue-and.html And, further updates on difference between questions and answers, please visit my blog @ http://onlydifferencefaqs.blogspot.in/