problem with null data in sql

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
 
J

Janaka

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
 
D

Dan Brussee

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.
 
L

luna

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
 
L

luna

yes no entry in the database

If objDR.IsDBNull(1) Then
seems to do the trick

thanks

mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top