Solved

Check for null string in row

Posted on 2011-09-12
2
264 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
Comment Utility
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
Comment Utility
Use IsDBNull()

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now