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. Visual Studio
  4. excel sheet

excel sheet

Scheduled Pinned Locked Moved Visual Studio
databasedesignhelp
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
    sudha_josyula
    wrote on last edited by
    #1

    The below code is for saving the database table data into excel sheet. private void Button1_Click(object sender, System.EventArgs e) { BindData(); Response.Clear(); Response.Buffer= true; Response.ContentType = "application/vnd.ms-excel"; Response.Charset = ""; this.EnableViewState = false; Response.AddHeader("content-disposition","attachment;filename=Emp.xls"); System.IO.StringWriter stringwrite=new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlwrite=new HtmlTextWriter(stringwrite); DataGrid1.RenderControl(htmlwrite); Response.Write(stringwrite.ToString()); Response.End(); } private void BindData() { oDA=new OleDbDataAdapter("select * from Emp",sqlconn); ds=new DataSet(); oDA.Fill(ds); DataGrid1.DataSource=ds; DataGrid1.DataBind(); } ----------------------------------------------------------------------------- The below code is for reading saved excel data private void Button2_Click(object sender, System.EventArgs e) { OleDbConnection con=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\EmpSai.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""); con.Open(); Response.Write("success"); con.Close(); } i am getting error at button2_click() event at con.open(); the error is: Exception Details: System.Data.OleDb.OleDbException: External table is not in the expected format.

    A 1 Reply Last reply
    0
    • S sudha_josyula

      The below code is for saving the database table data into excel sheet. private void Button1_Click(object sender, System.EventArgs e) { BindData(); Response.Clear(); Response.Buffer= true; Response.ContentType = "application/vnd.ms-excel"; Response.Charset = ""; this.EnableViewState = false; Response.AddHeader("content-disposition","attachment;filename=Emp.xls"); System.IO.StringWriter stringwrite=new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlwrite=new HtmlTextWriter(stringwrite); DataGrid1.RenderControl(htmlwrite); Response.Write(stringwrite.ToString()); Response.End(); } private void BindData() { oDA=new OleDbDataAdapter("select * from Emp",sqlconn); ds=new DataSet(); oDA.Fill(ds); DataGrid1.DataSource=ds; DataGrid1.DataBind(); } ----------------------------------------------------------------------------- The below code is for reading saved excel data private void Button2_Click(object sender, System.EventArgs e) { OleDbConnection con=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\EmpSai.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""); con.Open(); Response.Write("success"); con.Close(); } i am getting error at button2_click() event at con.open(); the error is: Exception Details: System.Data.OleDb.OleDbException: External table is not in the expected format.

      A Offline
      A Offline
      Asif Sayed
      wrote on last edited by
      #2

      Hi, In button_1 you are dealing with Emp.xls and in Button_2 you are trying to open EmpSai.xls! is this your simple mistake? Hope this helps. Difficult - > Challenging, this simple replacement made me take my life little easy;)

      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