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???
|