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

Discussion in 'ASP .Net' started by bienwell, Nov 21, 2006.

  1. bienwell

    bienwell Guest

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

    }

    }
    bienwell, Nov 21, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anonieko
    Replies:
    2
    Views:
    7,310
    JackStraw73
    Feb 12, 2008
  2. KK
    Replies:
    2
    Views:
    550
    Big Brian
    Oct 14, 2003
  3. bienwell
    Replies:
    2
    Views:
    4,145
    bienwell
    Jun 17, 2006
  4. Robbe Morris [C# MVP]

    asp.net extracting excel charts from an Excel file

    Robbe Morris [C# MVP], Dec 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    472
    Robbe Morris [C# MVP]
    Dec 15, 2006
  5. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,498
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
Loading...

Share This Page