Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Error when running ASP.NET program to READ Excel file. Please help !!!

Reply
Thread Tools

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

 
 
bienwell
Guest
Posts: n/a
 
      11-21-2006
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();

}

}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Excel reports ::::Excel 2003 Migration To Excel 2007 =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= ASP .Net 15 10-24-2007 01:34 PM
read a excel sheet using aspose.excel sajithkahawatta ASP .Net 3 04-19-2007 02:54 PM
Help: Program to read from EOR end of last read? snoopy_@excite.com Perl Misc 3 04-07-2006 12:32 PM
Help: Program to read from EOR end of last read? snoopy_@excite.com Java 3 04-07-2006 12:32 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments