Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null Dataset Row Produces System.IndexOutOfRangeException 1

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
US
I have a dataset which contains between 1-70 records. I also dimension 70 string variables which hold the "BundleID" value from each record. If I have 8 records in the dataset, the first 8 string variables will populate successfully, but then I get the following error on #9...
System.IndexOutOfRangeException: There is no row at position 9.

My code (similar for all 70 variables) looks like this...
Code:
If Not IsNothing(dataset.Tables("spMobileBundleIDSelect").Rows.Item(1)("BundleID")) Then StringVariable1 = dataset.Tables("spMobileBundleIDSelect").Rows.Item(1)("BundleID").ToString()
As you can see I'm trying to use Not IsNull to check if a record exists for the specific dataset row.

How can I check whether or not a dataset row exists without having this exception?

Thanks.
 
try using if not isdbnull look at the db

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thanks Rick - That's what we needed!
 
Remember to use .rows.count-1 if you are looping through the collection. .Count returns the 1-based value, where as .item(x) is 0-Based.

Code:
'This will work:
dim iRow as integer
for iRow = 0 to datatable.rows.count-1
 '...
next

'This will NOT work:
dim iRow as integer
for iRow = 1 to datatable.rows.count
 '...
next
[code]

-Rick

VB.Net Forum forum796    forum855 ASP.NET Forum
    [monkey][url=http://www.ringdev.com]I believe in killer coding ninja monkeys.[/url][monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top