Re: If row .IsNullOrEmpty
Row("Comp Address") is returning type Object. How about converting that object to a string and comparing to Null or Empty rather than doing the conversion to string on the return from the method. Alternatively, you could also perform a two step process where the first If checks for Null, then for an empty string. That's not as nice, though.
Re: If row .IsNullOrEmpty
I thought thats what I was doing with
Cstr(row("Comp Address")
Re: If row .IsNullOrEmpty
Almost, but you put the second ) in the wrong place.
What I was suggesting looks like this:
CStr(row("Comp Address")).IsNullOrEmpty
The problem is that you could also write that using .ToString rather than CStr, and one of the two throws an exception when the value is Null, but I can't remember which. I think CStr is the one you want to use.
Re: If row .IsNullOrEmpty
I had tried that previously, but I get blue squirrley line with message "Access of shared member, constant member or nested type through an instance; qualifying expression will not be evaluated
This seems to working well:
Code:
If row.IsNull("Comp Address") Then
compaddress.Text = " None Available"
Else : compaddress.Text = CStr(row("Comp Address"))
End If
Re: If row .IsNullOrEmpty
IsNullOrEmpty is, as the error message suggests, a Shared member, not an instance member. You should know how to use Shared members by now. You call it on the type and then pass the instance rather than calling it on the instance. Not surprisingly, the documentation has a code example but, not surprisingly, the documentation was apparently ignored.
First of all, the code you have now will display "None Available" if the field is NULL but not if it is empty. Is that really what you want? Will the address ever actually be empty as opposed to NULL? If you want to replace empty values as well as NULLs then that code will not work. If you only want to replace NULLs then that code can be written more succinctly as:
vb.net Code:
compaddress.Text = If(row.IsNull("Comp Address"), "None Available", CStr(row("Comp Address"))
If you want to replace NULL and empty values then you can do this:
vb.net Code:
Dim address = row("Comp Address").ToString()
compaddress.Text = If(String.IsNullOrEmpty(address), "None Available", address)