OledbException: Unrecoginzed Data Format - TechRepublic
General discussion
July 9, 2004 at 12:53 PM
roochisahney

OledbException: Unrecoginzed Data Format

by roochisahney . Updated 21 years, 4 months ago

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 discussion is locked

All Comments