problem with null data in sql

  • Thread starter Thread starter luna
  • Start date Start date
L

luna

could someone explain the meaning behind :- System.IndexOutOfRangeException:
firstname1

when the code is :-

If objDR("firstname1") Is System.DBNull.Value Then
firstname1.Text = ""
Else : firstname1.Text = objDR("fname1")
End If


and theres no entry in the database if theres an entry in the database there
isnt a problem
 
luna,

I take it objDR is a DataReader? Try using its method of
objDR.IsDBNull() - you'll have to use the ordinal number of "firstname1"
instead.
So your code will look more like:

If objDR.IsDBNull(0) Then
....
End If
 
Your comment that there is no entry in the database makes me think
that the objDR is empty, so there is no current record. This is very
different than a field having a null value. Check if objDR is nothing
(or null depending on language flavor) before testing. You should
probably handle a null record differently than a null field value.
 
that did the trick thanks!!

mark


Janaka said:
luna,

I take it objDR is a DataReader? Try using its method of
objDR.IsDBNull() - you'll have to use the ordinal number of "firstname1"
instead.
So your code will look more like:

If objDR.IsDBNull(0) Then
...
End If
 
Back
Top