Question : ado.net reading first sheet of excel file.

DataSet ds = null;
            //db connection for the excel file using ado.net
            OleDbConnection dbConnection = new OleDbConnection(
                                                    @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
                                                    + fileName
                                                    + @";Extended Properties=""Excel 8.0;HDR=YES;""");

            try
            {
                // Get the name of the first worksheet:
                dbConnection.Open();
               // DataTable dbSchema = dbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                DataTable dbSchema = dbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
                                                                   new object[] { null, null, null, "TABLE" });
                if (dbSchema == null || dbSchema.Rows.Count < 1)
                {
                    throw new Exception("Error: Could not determine the name of the first worksheet.");
                }
                //get the name of first sheet
                string firstSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();

This returns me the first sheeet name from the sorted list of sheet names ,not accordking to the actual order/ I want to readf always from 1st excel sheet. any suggestions???

Answer : ado.net reading first sheet of excel file.

It seems you are not the first with the same problem.

You can't get the information from the schema.

Try the following approach (a bit outdated code):

http://www.dotnet247.com/247reference/msgs/45/229488.aspx
Random Solutions  
 
programming4us programming4us