How to switch between sheets

Jun 17, 2014 at 12:35 PM
I need to get information from sheet1 "your details" and then sheet2 "your sites"
foreach (DataTable dt in result.Tables)
            {
                if (dt.TableName.ToLower().Contains("your details"))
                {
                    excelReader.Read();
                    ... do stuff
                 }
                 else if(dt.TableName.ToLower().Contains("your sites"))
                {
                    excelReader.Read();
                    ... This is the problem,  I'm still reading from sheet "your details"
                }
But when the code finds the sheet "your sites" and I call [excelReader.Read();] it is still reading from the first sheet...
Can anyone help ?
Jun 18, 2014 at 6:38 PM

It looks like you are using a mixture of dataset and idatareader. Just use one method.

Jun 19, 2014 at 10:48 AM
Thanks, I got it in the end... In casse anyone else lands here with the same problem - I found it easier to stick to datasets (easier to navigate & manipulate)
DataSet result = excelReader.AsDataSet();
            excelReader.IsFirstRowAsColumnNames = true;

            foreach (DataTable dt in result.Tables)
            {
                if(dt.TableName.ToLower().Contains("your sites"))
                {

                    DataSet ds = dt.DataSet;
                    DataTable Dt = ds.Tables["Your Sites"];

                    foreach (DataRow dr in Dt.Rows)
                    {
                        strSiteURL = (dr[1].ToString());
                        strCategory1 = (dr[2].ToString());
                        ....
                        ...
                    }
              }