Results 1 to 3 of 3

Thread: Null Value in C#

  1. #1
    HallMiller is offline Senior Member
    Join Date
    Dec 2009
    Posts
    251
    Rep Power
    3

    Default Null Value in C#

    I am learning C# programming language. I write a small program in which I have to check the null value. I have tried lot of code bit none of them worked out. So I want to know how to Check Null Value in C#..?? any help would be highly appreciated. Thanks in advanced.

  2. #2
    AllenBrown is offline Senior Member
    Join Date
    Dec 2009
    Posts
    240
    Rep Power
    3

    Default

    Try out this code, when you run this program you Check Null Value as an output result:

    Code:
    if(dr["AdmissionDate"] == DBNull.Value)
    {
    //Null value in AdmissionDate Column
    }
    else
    {	
    //Not Null
    }

  3. #3
    ScottWright is offline Senior Member
    Join Date
    Dec 2009
    Posts
    243
    Rep Power
    3

    Default

    Follow the steps for checking the null values in C#:

    1. Create the variable first. A variable should be declared before using it. You can use the following code for creating the variable :

    Code:
    string myNullVar = null;
    2. After that you will have to make sure that whether the variable is null or not. You can use the following code for that purpose :

    Code:
    if(myNullVar == null) {
    myNullVar = "RED";
    }
    3. Then you will have to check if the variable is not null. In a few cases, you may want to relocate the variable back to null. The following code is useful for that :

    Code:
    if(myNullVar != null) {
    myNullVar = null;
    }

Similar Threads

  1. Null pointer error in java
    By CoxWatson in forum Programming
    Replies: 2
    Last Post: 03-19-2010, 01:49 PM
  2. Null modem
    By AdamsClark in forum General Internet Terms
    Replies: 1
    Last Post: 03-06-2010, 03:04 PM
  3. In Java Script how to Check Null Value?
    By CruzPowell in forum Programming
    Replies: 1
    Last Post: 02-11-2010, 05:15 PM
  4. Null character
    By techno23 in forum Programming
    Replies: 0
    Last Post: 03-26-2008, 12:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48