0

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.

1 Answer 1

1

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;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.