Solved

Check for null string in row

Posted on 2011-09-12
2
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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