Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Checking for Null values

Checking for Null values

Scheduled Pinned Locked Moved ASP.NET
databasehelp
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srikantha_nagaraj
    wrote on last edited by
    #1

    Hi, I retrieving the value from Database. While retrieving i am checking for data is null or not. But if is not working properly. This is my code, tell me if any correction is required If dr is a datareader then, if (dr[0].ToString() == null) { //code } else { // code } Please help me.

    A A I 3 Replies Last reply
    0
    • S srikantha_nagaraj

      Hi, I retrieving the value from Database. While retrieving i am checking for data is null or not. But if is not working properly. This is my code, tell me if any correction is required If dr is a datareader then, if (dr[0].ToString() == null) { //code } else { // code } Please help me.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      srikantha_nagaraj wrote:

      But if is not working properly.

      What do you mean by not working Properly. What problem are you getting ? You can use String.IsNullOrEmpty() Method to implement it.

      string S=dr[0].ToString();
      if (String.IsNullOrEmpty(S) == true)
      {
      // Do your job !
      }

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      M 1 Reply Last reply
      0
      • S srikantha_nagaraj

        Hi, I retrieving the value from Database. While retrieving i am checking for data is null or not. But if is not working properly. This is my code, tell me if any correction is required If dr is a datareader then, if (dr[0].ToString() == null) { //code } else { // code } Please help me.

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        Check like this :

        if(DBNull.Value.equals(dr[0]))
        {
        //code
        }
        else
        {
        //code
        }

        This would be better.:rose:

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        1 Reply Last reply
        0
        • A Abhijit Jana

          srikantha_nagaraj wrote:

          But if is not working properly.

          What do you mean by not working Properly. What problem are you getting ? You can use String.IsNullOrEmpty() Method to implement it.

          string S=dr[0].ToString();
          if (String.IsNullOrEmpty(S) == true)
          {
          // Do your job !
          }

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          M Offline
          M Offline
          Manas Bhardwaj
          wrote on last edited by
          #4

          Abhijit Jana wrote:

          dr[0].ToString();

          This will fail if value of dr[0] IS NULL.

          Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

          1 Reply Last reply
          0
          • S srikantha_nagaraj

            Hi, I retrieving the value from Database. While retrieving i am checking for data is null or not. But if is not working properly. This is my code, tell me if any correction is required If dr is a datareader then, if (dr[0].ToString() == null) { //code } else { // code } Please help me.

            I Offline
            I Offline
            Inderjeet Kaur
            wrote on last edited by
            #5

            Handle it in database. While retrieving value use ISNULL(CULUMNNAME, 0.00) AS NewColumn Or if you want to handle it at code behind use as told in above replies

            Inderjeet Kaur Sr. Software Engg

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups