Avatar of zimmer9
zimmer9
Flag 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.
FallQueryACSToExcel.txt
.NET ProgrammingC#

Avatar of undefined
Last Comment
jmcmunn

8/22/2022 - Mon
jmcmunn

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)  ;-)
zimmer9

ASKER
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;");
            _conn.Open();
           
            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++)
ASKER CERTIFIED SOLUTION
jmcmunn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes