General discussion

Locked

OledbException: Unrecoginzed Data Format

By roochisahney ·
I'm trying to display Dataset from Excel file to ASPX page. I'm using OLEBD connection to do so but when trying to run my code..it gives me following error

Exception Details: System.Data.OleDb.OleDbException: Unrecognized database format 'c:\inetpub\wwwroot\ExcelData.xls'.

Here is the code of my application
// Create connection string variable. Modify the Data Source"

OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../ExcelData.xls"));
objConn.Open();

// The code to follow uses a SQL SELECT command to display the data from the worksheet.

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM myRange1", objConn);

// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.
DataSet objDataset1 = new DataSet();

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();

// Clean up objects.
objConn.Close();

I appreciate your help.
Thanks.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by ahar In reply to OledbException: Unrecogin ...

Review your connectionstring!
First, don't use JET (oudated and slow)
make an ODBC-SystemDSN
and use a connectionstring like
Provider=MSDASQL.1;Persist Security Info=False;Data Source=excel_test;Initial Catalog=<absolutepath>\<excel-file>

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums