Solved

Check for null string in row

Posted on 2011-09-12
2
267 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:jdhackett
2 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 36522530
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
0
 
LVL 18

Accepted Solution

by:
Cluskitt earned 500 total points
ID: 36522553
Use IsDBNull()

If Not IsDBNull(rowRenewal("User_" & iStage)) Then
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question