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. Problem in Connecting Excel File

Problem in Connecting Excel File

Scheduled Pinned Locked Moved C#
helpdatabaseannouncementcareer
2 Posts 1 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.
  • A Offline
    A Offline
    amaankhan
    wrote on last edited by
    #1

    private bool Connect() { string DB_Path= @"E:\Office Project\salary project\AttendanceSummary.csv"; string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";"; con = new OleDbConnection(Con_Str); con.Open(); string query = "SELECT SNO, ECODE, NAME, PRESENT, ABSENT, OFF, LEAVE, LWP, OTHOURS FROM [AttendanceSummary$]"; OleDbDataAdapter oda = new OleDbDataAdapter(query, con); DataSet ds = new DataSet(); oda.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.Update(); if (con.State == ConnectionState.Open) { MessageBox.Show("Connected"); return true; } else return false; } ====>>>> this code is working fine...........Problem is that when i am connecting other file "XYZ.XLS" which is having some text heading in the Top Rows................ its showing error ....... pls kindly help me Thanks in Advance.( sorry if any mistake i am very new to programming)

    A 1 Reply Last reply
    0
    • A amaankhan

      private bool Connect() { string DB_Path= @"E:\Office Project\salary project\AttendanceSummary.csv"; string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";"; con = new OleDbConnection(Con_Str); con.Open(); string query = "SELECT SNO, ECODE, NAME, PRESENT, ABSENT, OFF, LEAVE, LWP, OTHOURS FROM [AttendanceSummary$]"; OleDbDataAdapter oda = new OleDbDataAdapter(query, con); DataSet ds = new DataSet(); oda.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.Update(); if (con.State == ConnectionState.Open) { MessageBox.Show("Connected"); return true; } else return false; } ====>>>> this code is working fine...........Problem is that when i am connecting other file "XYZ.XLS" which is having some text heading in the Top Rows................ its showing error ....... pls kindly help me Thanks in Advance.( sorry if any mistake i am very new to programming)

      A Offline
      A Offline
      amaankhan
      wrote on last edited by
      #2

      Thanks I GOT :thumbsup: :)

      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