|
-
Mar 22nd, 2006, 07:49 AM
#1
Thread Starter
Member
[RESOLVED] Dealing with Nulls using the Datareader method...
Hello all,
I am after advice on the best method to deal with nulls returned from the DB when using the datareader method for gathering my data.
Here is a sample of my code:
'See if any data exists before continuing
If objData.DataReader.HasRows Then
'Read the first and only row of data
objData.DataReader.Read()
txtFirstName.Text = _
objData.DataReader.Item("FirstName").ToString.ToUpper
txtSurname.Text = _
objData.DataReader.Item("LastName").ToString.ToUpper
End If
I get an error when this code is run along the lines of 'cannot cast DBNull to string'.
Now I can sort out Nulls at the DB end, no problem, but I would prefer to do this at the client end.
I've looked into the IsDBNull function but just cannot get that to work for some reason. Can someone shine any light on this please?
Thank you
-
Mar 22nd, 2006, 08:40 AM
#2
Hyperactive Member
Re: Dealing with Nulls using the Datareader method...
I've used it like below with no probs.
VB Code:
If IsDBNull(dr.GetValue(7)) Then
oldtext = 0
Else
oldtext = CInt(dr.GetValue(7))
End If
-
Mar 22nd, 2006, 09:21 AM
#3
Thread Starter
Member
Re: Dealing with Nulls using the Datareader method...
Thanks
I could see that working, but it would be long way around as far as I can see, I was hoping for something short and sweet. For example, in vba I could do this:
txtSurname = Iif(Isnull(rs.firstname),"",rs.firstname) or something similar.
Is there a similar method I could use specifically for the datareader in vb?
-
Mar 22nd, 2006, 09:29 AM
#4
Thread Starter
Member
Re: Dealing with Nulls using the Datareader method...
Sorted, after the rebuild. The ToString sorts it out it seems.
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
|