Asp.net 位置0处没有行错误

Asp.net 位置0处没有行错误,asp.net,sql,vb.net,position,row,Asp.net,Sql,Vb.net,Position,Row,我有以下代码: Do Until i = dsSalesRep.Tables(0).Rows.Count strRepID = dsSalesRep.Tables(0).Rows(i)("repID").ToString strLBP = dsSalesRep.Tables(0).Rows(i)("officename").ToString strLBPEmail = dsSalesRep.Table

我有以下代码:

Do Until i = dsSalesRep.Tables(0).Rows.Count
                strRepID = dsSalesRep.Tables(0).Rows(i)("repID").ToString
                strLBP = dsSalesRep.Tables(0).Rows(i)("officename").ToString
                strLBPEmail = dsSalesRep.Tables(0).Rows(i)("cemail").ToString
                strCCRepEmail = dsSalesRep.Tables(0).Rows(i)("cc1").ToString
                strRepName = dsSalesRep.Tables(0).Rows(i)("firstname").ToString & " " & dsSalesRep.Tables(0).Rows(i)("lastname").ToString
                strRepEmail = dsSalesRep.Tables(0).Rows(i)("email").ToString
                strRepPhone = dsSalesRep.Tables(0).Rows(i)("phone").ToString

                searchStr3 = "SELECT * FROM LookupSalesRep WHERE repID='" & strRepID & "'"
                Dim SqlAdapter3 As New SqlDataAdapter(searchStr3, myConn2)
                Dim dsTerritories As New DataSet
                myConn2.Open()
                SqlAdapter3.Fill(dsTerritories)
                strCountry = dsTerritories.Tables(0).Rows(0)("country").ToString
                'strCountry = dsTerritories.Tables(0).Rows.Count.ToString
但是,当我运行网页时,它会给我一个错误:位置0处没有行

但是当我使用代码时

strCountry = dsTerritories.Tables(0).Rows.Count.ToString

strCountry获得正确的行数。请帮助:(

您处于一个循环中,在某个点上,表(dsTerritories.Tables(0))为空。请首先检查表是否为空:

If dsTerritories.Tables(0).Rows.Count > 0 Then
    strCountry = dsTerritories.Tables(0).Rows(0)("country").ToString
End If