Always have this problem whenever a DB query returns Null values for certain columns to my Datareader. I don't know how to check if any of the values returned are Null before setting the control Text property or SelectedIndex to it.
With the code below i get the following error message:
"Cast from type 'DBNull' to type 'String' is not valid"
===========================================================
Dim allocatedDA As Integer
Dim dr_id As SqlDataReader = users.GetSingleUserID(userId)
dr_id.Read()
allocatedDA.Text = CInt(dr_id("DA")
dr_id.Close()
===========================================================
I have tried this:
===========================================================
If Not IsDBNull(dr_id("UserID") Then
blahblah
End If
===========================================================
And this:
===========================================================
If Not (dr_id("UserID") = Nothing Then
blahblah
End If
===========================================================
Aswell as this:
===========================================================
If Not (dr_id("UserID") Is Nothing Then
blahblah
End If
===========================================================
But none of them seem to work! Help please.
cheers,
si
With the code below i get the following error message:
"Cast from type 'DBNull' to type 'String' is not valid"
===========================================================
Dim allocatedDA As Integer
Dim dr_id As SqlDataReader = users.GetSingleUserID(userId)
dr_id.Read()
allocatedDA.Text = CInt(dr_id("DA")
dr_id.Close()
===========================================================
I have tried this:
===========================================================
If Not IsDBNull(dr_id("UserID") Then
blahblah
End If
===========================================================
And this:
===========================================================
If Not (dr_id("UserID") = Nothing Then
blahblah
End If
===========================================================
Aswell as this:
===========================================================
If Not (dr_id("UserID") Is Nothing Then
blahblah
End If
===========================================================
But none of them seem to work! Help please.
cheers,
si