Solved

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

Posted on 2006-11-22
8
364 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
Comment Utility
It returns 1 table (even if empty).
0
 
LVL 10

Accepted Solution

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

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
Comment Utility
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
Comment Utility
Hi GSK_DEV, did this work for you ?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
You need to check for both conditions to be safe.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now