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

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

LVL 1
GSK_DEVAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Kinger247Connect With a Mentor Commented:
check for objDataSet.Tables(0).Rows.count instead.
0
 
Kinger247Commented:
It returns 1 table (even if empty).
0
 
Bob LearnedConnect With a Mentor Commented:
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
 
Kinger247Commented:
Hi GSK_DEV, did this work for you ?
0
 
Bob LearnedCommented:
You need to check for both conditions to be safe.
0
All Courses

From novice to tech pro — start learning today.