Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

I am wrting a C# Windows app in VS2005 and do you know how would I resolve the error _COMPlusExceptionCode -532459699 "IndexOutOfRangeException was unhandled. Cannot find table 0"?

I am developing a C# Windows application using VS2005. I use SQL Server 2005 as the back end database. Do you know how I can resolve the error:

"IndexOutOfRangeException was unhandled. Cannot find table 0."
_COMPlusExceptionCode -532459699

The offending statement is at the following line of code at the beginning of my FOR loop:  
i <= ds.Tables[0].Rows.Count - 1

This error occurs in my module titled FallQueryACSToExcel which I attached.
Avatar of jmcmunn
Flag of United States of America image

You should check your query to make sure it is returning the right information.  The call to adapter.fill is not gathering any data into the dataset in this case.

If ds.tables[0] is null (empty, meaning there are no tables at all!) then you would get the error you are seeing.  So...first I would try sending in a simple query rather than using the stored procedure.  like "Select Top 5 * from table" or whatever.  Then test your code and make sure it works.  If so, it is likely an error with the stored procedure.  Perhaps some syntax is wrong, or you are passing the wrong parameters.

But regardless of WHAT the issue causing this error is...the error means you have no tables in the dataset (or at least not one at index 0)  ;-)
Avatar of zimmer9


I tried running the following code and it works fine. I just substitued a query in place of the original stored procedure. My original code is in the attachment titled FallQueryACSToExcel.txt

private void FallQueryACSToExcel(string reportyr)
            int i = 0;
            int j = 0;
            string data = null;
            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlApp = new Excel.ApplicationClass();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            SqlConnection _conn = new System.Data.SqlClient.SqlConnection("Data Source=F,3;Initial Catalog=L;User ID =L;PWD=C;");
            SqlCommand command = new SqlCommand("SELECT * FROM tblFlACS", _conn);
            command.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "tblFlACS");                    
            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
Avatar of jmcmunn
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial