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. C# + Excel

C# + Excel

Scheduled Pinned Locked Moved C#
helpcsharpquestion
7 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
    Socheat Net
    wrote on last edited by
    #1

    Dear, I have one problem, when i connect from my app to excel and when display the result I lost 1 row, Why? Please help me

    Socheat

    F 1 Reply Last reply
    0
    • S Socheat Net

      Dear, I have one problem, when i connect from my app to excel and when display the result I lost 1 row, Why? Please help me

      Socheat

      F Offline
      F Offline
      fly904
      wrote on last edited by
      #2

      You need to be more specific. How did you connect to the excel? Was it the first row you lost?

      My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

      S 1 Reply Last reply
      0
      • F fly904

        You need to be more specific. How did you connect to the excel? Was it the first row you lost?

        My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

        S Offline
        S Offline
        Socheat Net
        wrote on last edited by
        #3

        Dear I Use like this string strCnn=""; strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"; strCnn += " Data source=" + openFileDialog1.FileName; strCnn += ";Extended Properties=Excel 8.0;"; OleDbConnection cn = new OleDbConnection(strCnn); cn.Open(); string strsql=""; strsql = "SELECT * FROM [sheet1$]"; OleDbDataAdapter da = new OleDbDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); int i=0; Application.DoEvents(); for (int k = 0; k < dt.Rows.Count; k++) { i++; dgvSource.Rows.Add(i.ToString(), dt.Rows[k][0].ToString()); } I got only 9 rows, but in fact in excel has 10 rows Thanks

        Socheat

        F 1 Reply Last reply
        0
        • S Socheat Net

          Dear I Use like this string strCnn=""; strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"; strCnn += " Data source=" + openFileDialog1.FileName; strCnn += ";Extended Properties=Excel 8.0;"; OleDbConnection cn = new OleDbConnection(strCnn); cn.Open(); string strsql=""; strsql = "SELECT * FROM [sheet1$]"; OleDbDataAdapter da = new OleDbDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); int i=0; Application.DoEvents(); for (int k = 0; k < dt.Rows.Count; k++) { i++; dgvSource.Rows.Add(i.ToString(), dt.Rows[k][0].ToString()); } I got only 9 rows, but in fact in excel has 10 rows Thanks

          Socheat

          F Offline
          F Offline
          fly904
          wrote on last edited by
          #4

          Which row is missing? Is it the first one? If it is then you will notice that it is being used as the column titles. Use strCnn += ";Extended Properties=\"Excel 8.0;HDR=No;\""; to stop using the first row as the column headers, the default is HDR=Yes.

          My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

          S 1 Reply Last reply
          0
          • F fly904

            Which row is missing? Is it the first one? If it is then you will notice that it is being used as the column titles. Use strCnn += ";Extended Properties=\"Excel 8.0;HDR=No;\""; to stop using the first row as the column headers, the default is HDR=Yes.

            My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

            S Offline
            S Offline
            Socheat Net
            wrote on last edited by
            #5

            Dear I lose the first row. I have include string connection like you wrote "HDR=No;" already but i got error Cound not find installable ISAM, so how can i do?

            Socheat

            F 1 Reply Last reply
            0
            • S Socheat Net

              Dear I lose the first row. I have include string connection like you wrote "HDR=No;" already but i got error Cound not find installable ISAM, so how can i do?

              Socheat

              F Offline
              F Offline
              fly904
              wrote on last edited by
              #6

              Apologies, I used used the incorrect syntax:

              string strCnn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=No;\"", openFileDialog1.FileName);

              My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

              S 1 Reply Last reply
              0
              • F fly904

                Apologies, I used used the incorrect syntax:

                string strCnn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=No;\"", openFileDialog1.FileName);

                My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

                S Offline
                S Offline
                Socheat Net
                wrote on last edited by
                #7

                Dear, Thanks, it work well now

                Socheat

                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