test for null value in returned datareader column

Hello Experts;

I am trying to test for null values in my datareader after returning a successful query.  Gathering information from other solutions found on this site, I managed to put together the below test.  It is not quite right, however, as I get an error message on run-time.  


If drPhysicalAddress.GetString(drPhysicalAddress.GetOrdinal("AptSuite")).IsNullOrEmpty = True Then
                        txtPhysicalAddressAptSuite.Text = ""
                    Else
                        txtPhysicalAddressAptSuite.Text = drPhysicalAddress.GetString(drPhysicalAddress.GetOrdinal("AptSuite"))
                    End If


error:
Argument not specified for parameter 'value' of 'Public Shared Function IsNullOrEmpty(value As String) As Boolean'.      


Is there a better way to test for null value?  What am I doing wrong?

Any help would be much appreciated.  Thank you in advance for your time.
LVL 2
gwosgoodIT MgrAsked:
Who is Participating?
 
gnarConnect With a Mentor Commented:
What about:

If String.IsNullOrEmpty(drPhysicalAddress("AptSuite").tostring) = True?
0
 
gnarCommented:
I think you need to rearrange it:



IsNullOrEmpty(drPhysicalAddress.GetString(drPhysicalAddress.GetOrdinal("AptSuite")))

Open in new window

0
 
gwosgoodIT MgrAuthor Commented:
gnar:

I made the changes you specified and now it is telling me that IsNullOrEmpty is not declared.  Do you know what I have to import or reference in order to use this function?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
appariCommented:
try

String.IsNullOrEmpty(drPhysicalAddress.GetString(drPhysicalAddress.GetOrdinal("AptSuite")))
0
 
gwosgoodIT MgrAuthor Commented:
appari:

Here is the change I made:

If String.IsNullOrEmpty(drPhysicalAddress.GetString(drPhysicalAddress.GetOrdinal("AptSuite"))) = True Then

Now it says the specified cast is not valid.  Any ideas?
0
 
gwosgoodIT MgrAuthor Commented:
shazam!

thanks gnar, that worked for some reason.  

I appreciate everyone's support.
0
All Courses

From novice to tech pro — start learning today.