Click to See Complete Forum and Search --> : Out of Range while using DataReader


kashif_82
08-06-2005, 11:35 AM
Hi, I am trying to read one row (it will only be one row based on Identity) and grabbing the data with DataReader:

cmd = NEW SQLCommand(sql, con)
'the rest of the code
dr = cmd.ExecuteReader
If dr.hasrows() then
dr.Read()
if NOT IsDbNull(dr("Name")) ANDALSO dr("Name").toString <> "" Then
Name= dr("Name").toString
End If
if NOT IsDbNull(dr("ShipAddress")) ANDALSO dr("ShippingAddress").toString <> "" Then
Address = dr("ShippingAddress").toString
End If


It works fine when it is grabbing the Name field but on ShippingAddress gives System.IndexOutOfRangeException. Both fields are nvarchar(50) and NON-NULL fields.

Phil Weber
08-06-2005, 12:53 PM
Are you sure the field is named "ShippingAddress" and not "ShipAddress"? Your code uses both.

kashif_82
08-06-2005, 01:41 PM
Phill you are a JOB savior...i have spent almost a 100 hours on this project in two weeks and now I am having problem with recognizing and debuggin my own code. it works like a charm.

BIG :) THANKS.