Solved

Check for null string in row

Posted on 2011-09-12
2
266 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

832 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