Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My asp.net web application is working fine on the localhost but when I go to the live server I am getting this error: System.IndexOutOfRangeException: Cannot find table 0. on this line of code: if (ds.Tables[0].Rows.Count > 0) means dataset does nnot have the table[0], how do I resolve this issue, please help me

Thanks in advance

C#
Server Error in '/' Application.
Cannot find table 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Cannot find table 0.

Source Error:


Line 41:                 else { OID = Request.QueryString["u"].ToString(); }
Line 42:               DataSet ds = myAdmin.getPassCodeAMIN(OID);
Line 43:                     if (ds.Tables[0].Rows.Count > 0)
Line 44:                         {
Line 45: 


Source File: c:\inetpub\vhosts\ip-pabx.com\httpdocs\LoginAction.aspx.cs    Line: 43

Stack Trace:
Posted
Comments
aarif moh shaikh 4-Jul-15 6:50am    
Where's your getPassCodeAMIN() function?

There in no table in ds. that's why it giving error.

check table count first
C#
if (ds.Tables.Count>0 && ds.Tables[0].Rows.Count > 0)
{

}

you better debug and check why getPassCodeAMIN method not returning datatable as you expected. in case of that method return empty data set you can add above validation to avoid exception
 
Share this answer
 
The dataset you are using is empty, because you are using wrong approach to load data into the dataset, to load data into dataset see this example:
First connect to the database you are working on:
Assuming it is sql server database.

C#
string strCon = "Data source = yourDataSource; Initial Catalog = DatabaseName; Integrated Security = SSPI;"; // for example if you are using windows authentication
            SqlConnection Conn = new SqlConnection(strCon);
            string strCmd = "select * from Company;";
            SqlDataAdapter sda = new SqlDataAdapter(strCmd, Conn);

            DataSet ds = new DataSet();
            sda.Fill(ds);
            
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Console.WriteLine(dr["compName"]);
            }
 
Share this answer
 
v2

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