|
-
Dec 6th, 2011, 05:03 PM
#1
Thread Starter
Frenzied Member
If row .IsNullOrEmpty
I need some hlep detecteing an empty row
HTML Code:
Dim row As DataRow
row = CType(Form1.DataGridView1.SelectedRows(0).DataBoundItem, DataRowView).Row
My error here is Option Strict On disallows late binding
HTML Code:
If CStr(row("Comp Address").IsNullOrEmpty) Then
compaddress.Text = " None Available"
End If
compaddress.Text = CStr(row("Comp Address"))
-
Dec 6th, 2011, 05:30 PM
#2
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.
My usual boring signature: Nothing
 
-
Dec 6th, 2011, 05:56 PM
#3
Thread Starter
Frenzied Member
Re: If row .IsNullOrEmpty
I thought thats what I was doing with
Cstr(row("Comp Address")
-
Dec 6th, 2011, 06:35 PM
#4
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.
My usual boring signature: Nothing
 
-
Dec 6th, 2011, 07:11 PM
#5
Thread Starter
Frenzied Member
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
-
Dec 6th, 2011, 11:24 PM
#6
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|