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. Visual Basic
  4. listview - iif statement

listview - iif statement

Scheduled Pinned Locked Moved Visual Basic
help
3 Posts 3 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.
  • C Offline
    C Offline
    Chrissy Callen
    wrote on last edited by
    #1

    Hi im trying to retrieve data using a listview but get the following error when running: An unhandled exception of type 'System.Data.SqlTypes.SqlNullValueException' occurred in system.data.dll Additional information: Data is Null. This method or property cannot be called on Null values. My code is as follows: listitems.subItems.Add(IIf(IsDBNull(.GetString(1)), .GetString(1), "")) can someone please help Chrissy Callen

    D 1 Reply Last reply
    0
    • C Chrissy Callen

      Hi im trying to retrieve data using a listview but get the following error when running: An unhandled exception of type 'System.Data.SqlTypes.SqlNullValueException' occurred in system.data.dll Additional information: Data is Null. This method or property cannot be called on Null values. My code is as follows: listitems.subItems.Add(IIf(IsDBNull(.GetString(1)), .GetString(1), "")) can someone please help Chrissy Callen

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Chrissy Callen wrote: listitems.subItems.Add(IIf(IsDBNull(.GetString(1)), .GetString(1), "")) This statement is sitting inside a 'With' block. It would help to know what that 'With' is. The GetString Method is being executed on a record that doesn't have a value. What you should be checking for first is if there is a value there, then execute GetString on it. Your trying to see if GetString returns a NULL, and if true, return the GetString NULL, if false, return an Empty string. What you should be doing is this: IIF( expression, Object if expression True, Object if expression False ) As Object

      listitems.subItems.Add( IIf( IsDBNull(), "", .GetString(1) ) )
      

      RageInTheMachine9532

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Chrissy Callen wrote: listitems.subItems.Add(IIf(IsDBNull(.GetString(1)), .GetString(1), "")) This statement is sitting inside a 'With' block. It would help to know what that 'With' is. The GetString Method is being executed on a record that doesn't have a value. What you should be checking for first is if there is a value there, then execute GetString on it. Your trying to see if GetString returns a NULL, and if true, return the GetString NULL, if false, return an Empty string. What you should be doing is this: IIF( expression, Object if expression True, Object if expression False ) As Object

        listitems.subItems.Add( IIf( IsDBNull(), "", .GetString(1) ) )
        

        RageInTheMachine9532

        P Offline
        P Offline
        Petros2004
        wrote on last edited by
        #3

        It has to do with the IIf statement. It evaluates both conditions, regardless of whether the first one is true or not. In other words, it does not short-circuit. You need to use the regular VB If-Else-End If construct to make this logic work the way you want.

        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