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. Stumped on IsDBNull on SQLDataReader

Stumped on IsDBNull on SQLDataReader

Scheduled Pinned Locked Moved ASP.NET
helpdatabaseworkspace
3 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.
  • A Offline
    A Offline
    AaronM_NZ
    wrote on last edited by
    #1

    Ok, this has me stumped. I am trying to get a single record from the DB, which may or may not be NULL. Dim cmdSelect As New SqlCommand("SELECT weblink FROM dbo.environment WHERE id = 7, sqlDB) sqlDB.Open() sqlRead = cmdSelect.ExecuteReader If Not sqlRead.IsDBNull(0) Then '...Do something with result Else '...Do something with NULL End If Yet when I do the test using 'If Not sqlRead.IsDBNull(0) Then', it throws and error: Invalid attempt to read when no data is present. Yes, I know theres nothing there, thats what I am trying to test. I cant find anything about how this should work, all examples seem to expect data to be coming back. Help!

    K 1 Reply Last reply
    0
    • A AaronM_NZ

      Ok, this has me stumped. I am trying to get a single record from the DB, which may or may not be NULL. Dim cmdSelect As New SqlCommand("SELECT weblink FROM dbo.environment WHERE id = 7, sqlDB) sqlDB.Open() sqlRead = cmdSelect.ExecuteReader If Not sqlRead.IsDBNull(0) Then '...Do something with result Else '...Do something with NULL End If Yet when I do the test using 'If Not sqlRead.IsDBNull(0) Then', it throws and error: Invalid attempt to read when no data is present. Yes, I know theres nothing there, thats what I am trying to test. I cant find anything about how this should work, all examples seem to expect data to be coming back. Help!

      K Offline
      K Offline
      Kelly Herald
      wrote on last edited by
      #2

      You must call sqlRead.Read() first. Kelly Herald Software Developer MPC

      A 1 Reply Last reply
      0
      • K Kelly Herald

        You must call sqlRead.Read() first. Kelly Herald Software Developer MPC

        A Offline
        A Offline
        AaronM_NZ
        wrote on last edited by
        #3

        Oh that was easy, thanks! I would have thought the .ExectueReader command would have sorted that out, but obviously not..

        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