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. System.DBNull returned for whitespace strings

System.DBNull returned for whitespace strings

Scheduled Pinned Locked Moved C#
databaseoraclehelpquestion
4 Posts 2 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.
  • G Offline
    G Offline
    GDavy
    wrote on last edited by
    #1

    I am using OracleDataReader to read data from our DB (oracle) The annoying thing is that in a certain column I have a string with a single white-space, however the datareader seems to convert this to a System.DBNull value, which is incorrect. Does anyone know if there is a setting on the OracleDataReader or perhaps the OracleConnection objects to prevent the conversion from white-space strings to DBNull? Thanks for any help you can provide, Davy

    P 1 Reply Last reply
    0
    • G GDavy

      I am using OracleDataReader to read data from our DB (oracle) The annoying thing is that in a certain column I have a string with a single white-space, however the datareader seems to convert this to a System.DBNull value, which is incorrect. Does anyone know if there is a setting on the OracleDataReader or perhaps the OracleConnection objects to prevent the conversion from white-space strings to DBNull? Thanks for any help you can provide, Davy

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Are you sure that you really have a single whitespace in that column? Try running a select on the table where that column is null. In Oracle, if you insert a trimmed string and the string length is zero, it actually stores it as null.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      G 1 Reply Last reply
      0
      • P Pete OHanlon

        Are you sure that you really have a single whitespace in that column? Try running a select on the table where that column is null. In Oracle, if you insert a trimmed string and the string length is zero, it actually stores it as null.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        G Offline
        G Offline
        GDavy
        wrote on last edited by
        #3

        Ok, this was a really stupid mistake of mine. Had written a PL/SQL block that replaced for certain rows in particular cases a null value with a singe white space string. BUT here comes the stupidity : forgot to commit... Was running my .NET app: I got DBNull, was double checking on the session that had run the PL/SQL block which was returning ofcourse the single character string. So committed the changes now and runs like a charm. X|

        P 1 Reply Last reply
        0
        • G GDavy

          Ok, this was a really stupid mistake of mine. Had written a PL/SQL block that replaced for certain rows in particular cases a null value with a singe white space string. BUT here comes the stupidity : forgot to commit... Was running my .NET app: I got DBNull, was double checking on the session that had run the PL/SQL block which was returning ofcourse the single character string. So committed the changes now and runs like a charm. X|

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          GDavy wrote:

          forgot to commit...

          Been there, seen it, got the T-shirt. Glad you got it sorted.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          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