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. General Programming
  3. C#
  4. Newbie: How to detect if an item in a DB record is null (mysql)...

Newbie: How to detect if an item in a DB record is null (mysql)...

Scheduled Pinned Locked Moved C#
databasequestionmysqlhelptutorial
8 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.
  • P Offline
    P Offline
    Phillip Hodges
    wrote on last edited by
    #1

    Hi all... Just a quick one... I am trying to pull data from a mysql database and I am falling foul of a null data error... I am querying a mysql database and pulling a record containing 38 items... However it is throwing errors because some of the items are null... What is the best way to detect if the item is null? So I can do something about it... Thanks in advance, Phil

    "Rules are for the obedience of fools and the guidance of wise men"

    _ E V 3 Replies Last reply
    0
    • P Phillip Hodges

      Hi all... Just a quick one... I am trying to pull data from a mysql database and I am falling foul of a null data error... I am querying a mysql database and pulling a record containing 38 items... However it is throwing errors because some of the items are null... What is the best way to detect if the item is null? So I can do something about it... Thanks in advance, Phil

      "Rules are for the obedience of fools and the guidance of wise men"

      _ Offline
      _ Offline
      _mubashir
      wrote on last edited by
      #2

      Can you provide the code giving error? Mubashir

      Every job is a self portrait of the person who did it.

      P 1 Reply Last reply
      0
      • _ _mubashir

        Can you provide the code giving error? Mubashir

        Every job is a self portrait of the person who did it.

        P Offline
        P Offline
        Phillip Hodges
        wrote on last edited by
        #3

        Here is a bit of the code: // build query string mysql_query = "SELECT * FROM rt_sip WHERE id = " + id + " ORDER BY id"; // submit query mysql_reader = mysql_send_query(mysql_query); while (mysql_reader.Read()) { // extract data from record temp_id = (int)mysql_reader[0]; temp_name = (string)mysql_reader[1]; temp_accountcode = (string)mysql_reader[2]; ... ... ... } Phil

        "Rules are for the obedience of fools and the guidance of wise men"

        G 1 Reply Last reply
        0
        • P Phillip Hodges

          Here is a bit of the code: // build query string mysql_query = "SELECT * FROM rt_sip WHERE id = " + id + " ORDER BY id"; // submit query mysql_reader = mysql_send_query(mysql_query); while (mysql_reader.Read()) { // extract data from record temp_id = (int)mysql_reader[0]; temp_name = (string)mysql_reader[1]; temp_accountcode = (string)mysql_reader[2]; ... ... ... } Phil

          "Rules are for the obedience of fools and the guidance of wise men"

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Use the IsDBNull method. Example:

          if (mysql_reader.IsDBNull(1) {
          temp_name = null;
          } else {
          temp_name = mysql_reader.GetString(1);
          }

          --- b { font-weight: normal; }

          P 1 Reply Last reply
          0
          • P Phillip Hodges

            Hi all... Just a quick one... I am trying to pull data from a mysql database and I am falling foul of a null data error... I am querying a mysql database and pulling a record containing 38 items... However it is throwing errors because some of the items are null... What is the best way to detect if the item is null? So I can do something about it... Thanks in advance, Phil

            "Rules are for the obedience of fools and the guidance of wise men"

            E Offline
            E Offline
            ednrgc
            wrote on last edited by
            #5

            Have you tried checking DBNull or IsDBNull()?

            1 Reply Last reply
            0
            • P Phillip Hodges

              Hi all... Just a quick one... I am trying to pull data from a mysql database and I am falling foul of a null data error... I am querying a mysql database and pulling a record containing 38 items... However it is throwing errors because some of the items are null... What is the best way to detect if the item is null? So I can do something about it... Thanks in advance, Phil

              "Rules are for the obedience of fools and the guidance of wise men"

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              DBValue.IsNull (or something like that) That should be DBNull.Value Good luck...

              V. Stop smoking so you can: enjoy longer the money you save.

              1 Reply Last reply
              0
              • G Guffa

                Use the IsDBNull method. Example:

                if (mysql_reader.IsDBNull(1) {
                temp_name = null;
                } else {
                temp_name = mysql_reader.GetString(1);
                }

                --- b { font-weight: normal; }

                P Offline
                P Offline
                Phillip Hodges
                wrote on last edited by
                #7

                Yep I tried that but got the same error message... Will keep looking...

                "Rules are for the obedience of fools and the guidance of wise men"

                G 1 Reply Last reply
                0
                • P Phillip Hodges

                  Yep I tried that but got the same error message... Will keep looking...

                  "Rules are for the obedience of fools and the guidance of wise men"

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  Phillip Hodges wrote:

                  Yep I tried that but got the same error message...

                  Then you did something wrong, because that method works. Where exactly do you get the error message, and what exactly is the error message?

                  --- b { font-weight: normal; }

                  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