BlakeMcKenna
asked on
Checking for NULL Value?
I know this is an elementary question but I still get stuck on it and do it inadvertently at times, but when retrieving values from a database result set, how do you prevent a NULL Value Error. For example, if a Database Field is defined as a numeric but contains nothing, it will return a NULL value. How can I prevent an exception from happening. Because currently I'm getting the following error:
"Conversion from type 'DBNull' to type 'Integer' is not valid"
"Conversion from type 'DBNull' to type 'Integer' is not valid"
ASKER
Ok...this is what I had!
clsDE.rangeUnitType_ID = If (row("unitType_ID").ToString.Length = 0, DBNull.Value, row("unitType_ID"))
ASKER
Ok,
I just got the following error on the below line of code (see attached image).
I just got the following error on the below line of code (see attached image).
clsDE.serialNO = If(row.Cells(3).Value <> DBNull.Value, row.Cells(3).Value, "")
Screenshot.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Fernando...that worked!
Not a problem BlakeMcKenna, glad to help.
e.g.
Open in new window