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. General Programming
  3. C#
  4. estblishing a conection of a excel sheet with C# application

estblishing a conection of a excel sheet with C# application

Scheduled Pinned Locked Moved C#
workspacecsharpdesignsysadminsecurity
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.
  • S Offline
    S Offline
    swtlibra
    wrote on last edited by
    #1

    i m trying to connecting the excel sheet with C# application but getting the error "External table is not in the expected format." i have written the following lines of code

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.OleDb;

    public partial class excelform : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    // Create connection string variable. Modify the "Data Source"
    // parameter as appropriate for your environment.
    string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" +
    ("Data Source=" + Server.MapPath("excelsht.xlsx") +
    // or use instead of Excel 8.0 - Excel 5.0
    ";Extended Properties=\"Excel 8.0;\""));
    string SSQL = "SELECT * from [excelsht$]";

        // here use oleDataReader
        OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn);
        DataSet ds = new DataSet();
         oleDA.Fill(ds);
        GridView1.DataSource = ds.Tables\[0\].DefaultView; 
        GridView1.DataBind();  
    }
    

    }

    A 1 Reply Last reply
    0
    • S swtlibra

      i m trying to connecting the excel sheet with C# application but getting the error "External table is not in the expected format." i have written the following lines of code

      using System;
      using System.Collections;
      using System.Configuration;
      using System.Data;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.HtmlControls;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Data.OleDb;

      public partial class excelform : System.Web.UI.Page
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      // Create connection string variable. Modify the "Data Source"
      // parameter as appropriate for your environment.
      string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" +
      ("Data Source=" + Server.MapPath("excelsht.xlsx") +
      // or use instead of Excel 8.0 - Excel 5.0
      ";Extended Properties=\"Excel 8.0;\""));
      string SSQL = "SELECT * from [excelsht$]";

          // here use oleDataReader
          OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn);
          DataSet ds = new DataSet();
           oleDA.Fill(ds);
          GridView1.DataSource = ds.Tables\[0\].DefaultView; 
          GridView1.DataBind();  
      }
      

      }

      A Offline
      A Offline
      Ankur m
      wrote on last edited by
      #2

      See this post: http://forums.asp.net/t/1088515.aspx[^]. Hope it helps.

      ..Go Green..

      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