Reputation: 30303
In web application, i write the code for displaying the data in excel sheet to gridview. it is working fine but, can i track the sheet name of that particular excel sheet. For example i have sample.xls in that how can i find the sheet name. i write the query like this
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
How can i find the sheet name of the particular excel and if the excel sheet having more than one sheet then how can i display the data. can you help me.
Upvotes: 0
Views: 208
Reputation: 94645
Use OleDbConnection.GetOleDbSchemaTable Method.
using (OleDbConnection connection = new
OleDbConnection(connectionString))
{
connection.Open();
DataTable schemaTable = connection.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables,
new object[] { null, null, null, "TABLE" });
return schemaTable;
}
Upvotes: 1