Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dsData = Data.GetDataSet(sqlData, GlobalParameters.conn)
            For Each dr As DataRow In dsData.Tables(0).Rows


The lines above, for some reason (I'm completely clueless) work perfectly when I'm running the site on localhost, but it won't work when uploaded onto a server. it for some reason comes up with the following error message even though the sql query is correct (and its been tested)

System.IndexOutOfRangeException: Cannot find table 0. at System.Data.DataTableCollection.get_Item(Int32 index) at Website.AdAppointments.btnSendAppointments_Click(Object sender, EventArgs e) in (FILE LOCATION):line 224

Line 224 is the beginning of the For loop.

Thanks a lot :)
Posted
Updated 24-Apr-11 2:46am
v2
Comments
Ed Nutting 24-Apr-11 9:16am    
Is the data given to your server the same as the data being returned to your local host? Do you have a permissions problem on your server that returns a blank collection of tables or similar? Have you tried simply getting your page to dispay how many tables are in the dsData.Tables collection?

It is probably trying to bind a data table to a dataset which does not have a table because no results were returned.

before using the datatables check for its existance:
VB
if (DataSet1.Tables.Count > 0)
 
Share this answer
 
Comments
Peter Liaros 24-Apr-11 18:15pm    
okay... ill give that a go
Peter Liaros 24-Apr-11 18:41pm    
yeh, no table exists, according to that line.
Om Prakash Pant 26-Apr-11 2:59am    
Try :
dsData = Data.GetDataSet(sqlData, GlobalParameters.conn)
if (dsData.Tables.Count > 0)
For Each dr As DataRow In dsData.Tables(0).Rows
.
.
System.IndexOutOfRangeException: Cannot find table 0. at
This error has nothing to do with server or local environment. It simple means that the dataset returned has no tables and thus when you try to access a table(assuming it is there), it throws an error.

Though, it's already suggested that make sure you check if the table exists or not before using it. Further, just considering any environemnt thing, it might be that the connection string is not proper(is wrong) and the dataset is not returned/formed correctly and thus you face an error. Just make sure that the data is returned as in local environment and then it should be fine.
 
Share this answer
 
Comments
Peter Liaros 24-Apr-11 18:13pm    
I run many SQL query's on this site and they all work.. It's just this page that decides to be a pain in the ass, so its nothing wrong with the connection string
Sandeep Mewara 25-Apr-11 0:28am    
Then your query is not returning any data for this page. Check with raw SQL on database. As stated, error is because of no data returned.

Also see if it's getting timedout or so? You might have handled/suppressed the errors of DB internally. Debugging too should help.
The dataset is not returning values. May be check your database connection string whether it points to the wright database.
 
Share this answer
 
Comments
Peter Liaros 24-Apr-11 18:13pm    
I run many SQL query's on this site and they all work.. It's just this page that decides to be a pain in the ass, so its nothing wrong with the connection string

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900