Error when running ASP.NET program to READ Excel file. Please help !!!

B

bienwell

Hi

I've tried this program from a sample posted on-line to open an Excel file,
read data and display on the Grid View. I'm using Visual Studio 2005 to
save this file. The program compiled OK. When I ran this file from Visual
Studio, I've got an alert message with this error message :

OLEDBException was unhandled by user code
Could not find installable ISAM


Troubleshooting tips:
Get general help for this exception

The error pointed to this line : objConn.Open();


The excel file is in the same location C:\VS2005_DEV with the aspx.cs file.


Please help me to define this problem.

Thanks in advance.

===================================================

using System;

using System.Data;

using System.Data.OleDb;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class ReadExcel : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{



String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +

"DataSource=" + Server.MapPath("VS2005_DEV\\ExcelData.xls") +

"Extended Properties=Excel 8.0;";

// Create connection object by using the preceding connection string.

OleDbConnection objConn = new OleDbConnection(sConnectionString);


// Open connection with the database.

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");


// Bind data to DataGrid control.

GridView1.DataSource = objDataset1.Tables[0].DefaultView;

GridView1.DataBind();


// Clean up objects.

objConn.Close();

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top