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