Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Accessing Excel data from WebForm

Accessing Excel data from WebForm

Scheduled Pinned Locked Moved ASP.NET
helpquestioncsharpcssasp-net
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DotNet_Newbie
    wrote on last edited by
    #1

    Hello All, I have a quick question!!! I have an excel file (.xls) with one sheet (Sheet1) with 4 columns, I’m trying to access the data in this file from an ASP.Net application, but no luck. Here is what I did so far

    string conString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("ExcelData.xls") + ";" + "Extended Properties=Excel 8.0;";
    OleDbConnection con = new OleDbConnection(conString);
    con.Open();
    OleDbDataAdapter da = new OleDbDataAdapter("Select * from ExcelData", conString);
    DataSet ds = new DataSet("ds");
    da.Fill(ds);
    

    When I try to run that I get the following error

    The Microsoft Jet database engine could not find the object 'ExcelData'. Make sure the object exists and that you spell its name and the path name correctly. 
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'ExcelData'. Make sure the object exists and that you spell its name and the path name correctly.
    
    Source Error: 
    
    Line 55: 			OleDbDataAdapter da = new OleDbDataAdapter("Select * from [ExcelData]", conString);
    Line 56: 			DataSet ds = new DataSet("ds");
    Line 57: 			da.Fill(ds);
    Line 58: 			/// Put the Data Grid Here.
    Line 59: 			con.Close();
    

    So, I was wondering if any one have an idea on how to access the data from an excel sheet from an ASP.Net form.? Any help would be greatly appreciated. Thank you all in Advance.

    M 1 Reply Last reply
    0
    • D DotNet_Newbie

      Hello All, I have a quick question!!! I have an excel file (.xls) with one sheet (Sheet1) with 4 columns, I’m trying to access the data in this file from an ASP.Net application, but no luck. Here is what I did so far

      string conString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("ExcelData.xls") + ";" + "Extended Properties=Excel 8.0;";
      OleDbConnection con = new OleDbConnection(conString);
      con.Open();
      OleDbDataAdapter da = new OleDbDataAdapter("Select * from ExcelData", conString);
      DataSet ds = new DataSet("ds");
      da.Fill(ds);
      

      When I try to run that I get the following error

      The Microsoft Jet database engine could not find the object 'ExcelData'. Make sure the object exists and that you spell its name and the path name correctly. 
      
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
      
      Exception Details: System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'ExcelData'. Make sure the object exists and that you spell its name and the path name correctly.
      
      Source Error: 
      
      Line 55: 			OleDbDataAdapter da = new OleDbDataAdapter("Select * from [ExcelData]", conString);
      Line 56: 			DataSet ds = new DataSet("ds");
      Line 57: 			da.Fill(ds);
      Line 58: 			/// Put the Data Grid Here.
      Line 59: 			con.Close();
      

      So, I was wondering if any one have an idea on how to access the data from an excel sheet from an ASP.Net form.? Any help would be greatly appreciated. Thank you all in Advance.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      I think the error message is quite clear. The ExcelData is not a valid object that can be used in the query statement. For example, I want to read data from the 'Sheet1' sheet in the .xls file. The command text looks something like this:

      string command = "SELECT * FROM [Sheet1$]";

      Remember to use the $ after the object you make a reference.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups