Click here to Skip to main content
15,879,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am using vs2010 and c# asp.net i want to read Excel File.I am using following code but i get the Error Message("Error :The Microsoft Jet database engine could not find the object 'ExportData$'. Make sure the object exists and that you spell its name and the path name correctly."). any one help me how to solve the problem.

C#
string strFileType = Path.GetExtension(FileUpload1.FileName).ToLower();
        string path = FileUpload1.PostedFile.FileName;
        //Connection String to Excel Workbook
        if (strFileType.Trim() == ".xls")
        {
            connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
        }
        else if (strFileType.Trim() == ".xlsx")
        {
            connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
        }
        string query = "SELECT [UserName],[Education],[Location] FROM [ExportData$]";
        OleDbConnection conn = new OleDbConnection(connString);
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        OleDbCommand cmd = new OleDbCommand(query, conn);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);



thanks Advance!..
Posted
Updated 4-Oct-15 22:19pm
v2
Comments
DamithSL 5-Oct-15 2:46am    
do you have scheet called ExportData?
Member 11889799 5-Oct-15 2:52am    
Yes. My Sheet Name is ExportData.

1 solution

You can use the following code to check the names of the sheets in the Excel file:
C#
DataTable schemaTable = dbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null });
    
foreach (DataRow dataRow in schemaTable.Rows)
{
    string tableName = dataRow["TABLE_NAME"].ToString();	// gets the sheet name from each schema entry
    if (!tableName.EndsWith("_"))
    {
        // some code to display the name
    }
}
 
Share this answer
 
Comments
Member 11889799 5-Oct-15 5:24am    
Dear Richard.
I am using your code but it is not working. SchemaTable.Rows count is 0 but my xlsx have a more rows and Columns why it is not read.
Richard MacCutchan 5-Oct-15 5:41am    
It souns like something is wrong with your file.
Member 11889799 5-Oct-15 5:59am    
Dear Richard.

Can you Give me the any idea to which one is wrong of my file. i am using microsoft office 2007.
Richard MacCutchan 5-Oct-15 6:03am    
You will need to check it yourself. But make sure you check the file that has been uploaded and not the original.
Member 11889799 5-Oct-15 6:39am    
Thanks for your Suggestions i ll check it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900