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. selecting data from excel sheet

selecting data from excel sheet

Scheduled Pinned Locked Moved ASP.NET
cssquestion
4 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 have to write a code for for copying a selected data from excel sheet to data grid now i m confused that whether i have to open the excel sheet with the program of had to show it to the form because i can't show the whole sheet to the datagrid (as its a requirement of a program) and after opening the sheet how i can copy the data from excel sheet display it on the datagrid any ideas ??????

    G 1 Reply Last reply
    0
    • S swtlibra

      i have to write a code for for copying a selected data from excel sheet to data grid now i m confused that whether i have to open the excel sheet with the program of had to show it to the form because i can't show the whole sheet to the datagrid (as its a requirement of a program) and after opening the sheet how i can copy the data from excel sheet display it on the datagrid any ideas ??????

      G Offline
      G Offline
      Gaurav Dudeja India
      wrote on last edited by
      #2

      Use this function

      public static DataTable getDataTable(string strFilename)
      {
      string SQL = "select * from [Sheet1$]";
      string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFilename + ";";
      connectionString += @"Extended Properties=""Excel 12.0;HDR=YES;""";
      OleDbConnection conn = new OleDbConnection(connectionString);
      OleDbCommand cmd = new OleDbCommand(SQL, conn);
      DataTable dt = new DataTable();
      OleDbDataAdapter da = new OleDbDataAdapter(cmd);
      da.Fill(dt);
      da.Dispose();
      conn.Dispose();
      cmd.Dispose();
      return dt;
      }

      Gaurav Dudeja http://www.gdinfotechindia.com
      Dont be afraid of changing your life to better !

      S 1 Reply Last reply
      0
      • G Gaurav Dudeja India

        Use this function

        public static DataTable getDataTable(string strFilename)
        {
        string SQL = "select * from [Sheet1$]";
        string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFilename + ";";
        connectionString += @"Extended Properties=""Excel 12.0;HDR=YES;""";
        OleDbConnection conn = new OleDbConnection(connectionString);
        OleDbCommand cmd = new OleDbCommand(SQL, conn);
        DataTable dt = new DataTable();
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        da.Fill(dt);
        da.Dispose();
        conn.Dispose();
        cmd.Dispose();
        return dt;
        }

        Gaurav Dudeja http://www.gdinfotechindia.com
        Dont be afraid of changing your life to better !

        S Offline
        S Offline
        swtlibra
        wrote on last edited by
        #3

        thnx for ur reply but it is simply the binding of excel sheet to datagrid but i have to copy selected data from excel sheet means when user click on certain record in excel sheet it gets copied in datagrid okzzz and plz do tell me also that how to open excel sheet with program for copying the data from it thnx in advance

        G 1 Reply Last reply
        0
        • S swtlibra

          thnx for ur reply but it is simply the binding of excel sheet to datagrid but i have to copy selected data from excel sheet means when user click on certain record in excel sheet it gets copied in datagrid okzzz and plz do tell me also that how to open excel sheet with program for copying the data from it thnx in advance

          G Offline
          G Offline
          Gaurav Dudeja India
          wrote on last edited by
          #4

          sorry i never do this so no idea.

          Gaurav Dudeja http://www.gdinfotechindia.com
          Dont be afraid of changing your life to better !

          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