Im kinda going a little crazy here. I moved my web application to a server and im getting this error below, but on my localhost it works great. Im kinda at a loss of what i should try. Any help would be very much appreciated. Im finding that the error has to have something to do with the dataset not pulling back any data, when I do a for each statement. But the weird thing is that I do a for each statement on another page and it works fine. Here is 开发者_高级运维my for each statement, that im assuming doesnt work. The reason im assuming it b/c when i test it on local it works fine:
Dim retObj As New ClassLibrary1.sql_class
For Each row As DataRow In retObj.sel_all_email_list(company).tables(0).rows
email += row("EMAIL_ADDRESS") & "/"
Next
'***************************** sql_class
query = "SELECT * " _
& " FROM EMAIL_LIST " _
& " WHERE UCASE(COMPANY) = '" & company & "'"
Dim adapter As New OleDbDataAdapter(query, myConnection)
Dim ds As New DataSet
Try
myConnection.Open()
adapter2.Fill(ds, "test_table")
*returns the dataset, didnt want to type all of the code
Catch ex As Exception
Finally
myConnection.Close()
End Try
'*****************************************************
Error:
Exception Details: System.IndexOutOfRangeException: Cannot find table 0.
Check the SQL DB running in Production.
The SQL statement used to fill the Dataset isn't returning any data. That leads to the Dataset not having any tables.
As a result when you make your call to Dataset.Tables(0)
a System.IndexOutOfRangeException
gets thrown (as there are no tables in the Tables collection).
You can mitigate against this by calling Dataset.Tables.Count
to ensure it has items before attempting to access the collection.
If retObj.sel_all_email_list(company).tables.count > 0 Then
'Do something
End If
精彩评论