Solved

System.IndexOutOfRangeException: There is no row at position 0.

Posted on 2006-11-22
8
371 Views
Last Modified: 2012-06-27
I have the following code  and when i traced the value for objDataSet.Tables.Count returns 1 and then errors out at the nextline (ie odr = objDataSet.Tables(0).Rows(0)
)

WHat could be the issue.

Here is the code snippet

        Dim objDAL As New MECDAL
        Dim objEntity As New MECEntity
        Dim objDataSet As DataSet
        Dim odr As DataRow
        objDataSet = objMECDAL.RetrieveMECGroups(lMECGroupID)
        If objDataSet.Tables.Count > 0 Then

            odr = objDataSet.Tables(0).Rows(0)

   .....

end if

0
Comment
Question by:GSK_DEV
  • 3
  • 2
8 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17998408
It returns 1 table (even if empty).
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 250 total points
ID: 17998410
check for objDataSet.Tables(0).Rows.count instead.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
ID: 17998700
Check this way:

    If objDataSet.Tables.Count > 0 AndAlso objDataSet.Tables(0).Rows.Count > 0 Then

The 'AndAlso' operator is a shortcut logical operator that if the first expression isn't True, the second part isn't evaluated.

Bob
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18015931
Hi GSK_DEV, did this work for you ?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18208065
You need to check for both conditions to be safe.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question