Solved

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

Posted on 2006-11-22
8
374 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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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