Link to home
Start Free TrialLog in
Avatar of jdhackett
jdhackettFlag for Ireland

asked on

Check for null string in row

Hi
I'm looping through the columns in a row, and I need to find out if a column contains a null value. So I have code as follows:

For iStage = 1 To MAX_STAGES               
               If Not String.IsNullOrEmpty(rowRenewal("User_" & iStage)) Then

Open in new window


Unfortunately, a null value will actually produce this message:
"Conversion from type 'DBNull' to type 'String' is not valid."

Is there a different way I could check for the null value in this case?
Thanks
Avatar of Bardobrave
Bardobrave
Flag of Spain image

Try this:

For iStage = 1 To MAX_STAGES              
               If Not String.IsNullOrEmpty(rowRenewal("User_" & iStage).ToString()) Then

If it don't work try to detect the null value before assigning it to the string

For iStage = 1 To MAX_STAGES              
               If Not rowRenewal("User_" & iStage) = null then
ASKER CERTIFIED SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial