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. Fetch data from Excel Sheet

Fetch data from Excel Sheet

Scheduled Pinned Locked Moved ASP.NET
databasecsharphelpasp-net
8 Posts 4 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.
  • C Offline
    C Offline
    cheguri
    wrote on last edited by
    #1

    Dear friends, I want to fetch data from Excel sheet sheet1 using ASP.NET with C# and store the data in SqlServer database table using BulkCopy method. I am able to fetch complete excelsheet data, but I want only some rows. I want sql statement to fetch the data. Excel sheet contains one Date column. I want to fetch data from only particular dated rows. I am writing the following query select * from [Sheet1$] where Date=21/04/10 It is giving me error datatype mismatch. Please, can anyone help me. It's very urgent. Pls.... Thanks, Dileep.

    A B T 3 Replies Last reply
    0
    • C cheguri

      Dear friends, I want to fetch data from Excel sheet sheet1 using ASP.NET with C# and store the data in SqlServer database table using BulkCopy method. I am able to fetch complete excelsheet data, but I want only some rows. I want sql statement to fetch the data. Excel sheet contains one Date column. I want to fetch data from only particular dated rows. I am writing the following query select * from [Sheet1$] where Date=21/04/10 It is giving me error datatype mismatch. Please, can anyone help me. It's very urgent. Pls.... Thanks, Dileep.

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      Try the following query: select * from [Sheet1$] where Date='04/21/2010' Note that the date should be in mm/dd/yyyy format and within single quote(').

      Anurag Gandhi.
      http://www.gandhisoft.com
      Life is a computer program and every one is the programmer of his own life.

      C 1 Reply Last reply
      0
      • A Anurag Gandhi

        Try the following query: select * from [Sheet1$] where Date='04/21/2010' Note that the date should be in mm/dd/yyyy format and within single quote(').

        Anurag Gandhi.
        http://www.gandhisoft.com
        Life is a computer program and every one is the programmer of his own life.

        C Offline
        C Offline
        cheguri
        wrote on last edited by
        #3

        Dear Anurag, I am still getting this following error. [System.Data.OleDb.OleDbException] = {"Data type mismatch in criteria expression."} I have written the following code. filename = path + "SS_EmpLoginTimings.xls"; string s = "provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=" + filename + ";Extended Properties=Excel 8.0;"; OleDbConnection con = new OleDbConnection(s); con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$] where Date='04/21/2010'", con); DataSet ds = new DataSet(); da.Fill(ds); DataTable dt = ds.Tables[0]; BulkCopyData(dt, "SS_EmpLoginTimings"); public bool BulkCopyData(DataTable dt, string tblName) { SqlBulkCopy bulk = new SqlBulkCopy(conn); bulk.DestinationTableName = tblName; conn.Open(); bulk.WriteToServer(dt); conn.Close(); return true; } Please help me. It's very urgent. I need to finish this work by today evening. Pls pls pls... Regards, Dileep.

        B 1 Reply Last reply
        0
        • C cheguri

          Dear Anurag, I am still getting this following error. [System.Data.OleDb.OleDbException] = {"Data type mismatch in criteria expression."} I have written the following code. filename = path + "SS_EmpLoginTimings.xls"; string s = "provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=" + filename + ";Extended Properties=Excel 8.0;"; OleDbConnection con = new OleDbConnection(s); con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$] where Date='04/21/2010'", con); DataSet ds = new DataSet(); da.Fill(ds); DataTable dt = ds.Tables[0]; BulkCopyData(dt, "SS_EmpLoginTimings"); public bool BulkCopyData(DataTable dt, string tblName) { SqlBulkCopy bulk = new SqlBulkCopy(conn); bulk.DestinationTableName = tblName; conn.Open(); bulk.WriteToServer(dt); conn.Close(); return true; } Please help me. It's very urgent. I need to finish this work by today evening. Pls pls pls... Regards, Dileep.

          B Offline
          B Offline
          Baconbutty
          wrote on last edited by
          #4

          Have you got da and ds the wrong way round in the da.fill(ds)? It's while since I coded anything like this so I could be totally wrong. Maybe try putting the criteria as Date = '21-Apr-2010'.

          1 Reply Last reply
          0
          • C cheguri

            Dear friends, I want to fetch data from Excel sheet sheet1 using ASP.NET with C# and store the data in SqlServer database table using BulkCopy method. I am able to fetch complete excelsheet data, but I want only some rows. I want sql statement to fetch the data. Excel sheet contains one Date column. I want to fetch data from only particular dated rows. I am writing the following query select * from [Sheet1$] where Date=21/04/10 It is giving me error datatype mismatch. Please, can anyone help me. It's very urgent. Pls.... Thanks, Dileep.

            B Offline
            B Offline
            Baconbutty
            wrote on last edited by
            #5

            http://www.experts-exchange.com/Programming/Languages/.NET/Q_25020438.html[^] Try that page - scroll down to the bottom and look for postings by sbsnewbie

            1 Reply Last reply
            0
            • C cheguri

              Dear friends, I want to fetch data from Excel sheet sheet1 using ASP.NET with C# and store the data in SqlServer database table using BulkCopy method. I am able to fetch complete excelsheet data, but I want only some rows. I want sql statement to fetch the data. Excel sheet contains one Date column. I want to fetch data from only particular dated rows. I am writing the following query select * from [Sheet1$] where Date=21/04/10 It is giving me error datatype mismatch. Please, can anyone help me. It's very urgent. Pls.... Thanks, Dileep.

              T Offline
              T Offline
              T M Gray
              wrote on last edited by
              #6

              How consistant is the data in your spreadsheet? Do all of the rows have dates in the date column? The Excel database driver determines the datatype of each column by the values in the first 10 rows. If your first ten rows have nothing in the date column or have other text like N/A or -, then that column will not be considered a date and you can't query it like a date.

              C 2 Replies Last reply
              0
              • T T M Gray

                How consistant is the data in your spreadsheet? Do all of the rows have dates in the date column? The Excel database driver determines the datatype of each column by the values in the first 10 rows. If your first ten rows have nothing in the date column or have other text like N/A or -, then that column will not be considered a date and you can't query it like a date.

                C Offline
                C Offline
                cheguri
                wrote on last edited by
                #7

                Dear friend, All the rows in that column are having date only. I don't know what's wrong. I have tried in many ways. I am getting the following error. [System.Data.OleDb.OleDbException] = {"Data type mismatch in criteria expression."} Since last day afternoon, I am struggling for this. I have written queries in all following possible ways. select * from [sheet1$] where LoginDate='21/04/10' select * from [sheet1$] where LoginDate='21/04/2010' select * from [sheet1$] where LoginDate='21-04-10' select * from [sheet1$] where LoginDate='21-04-2010' select * from [sheet1$] where LoginDate='21-Apr-10' select * from [sheet1$] where LoginDate='21-Apr-2010' select * from [sheet1$] where LoginDate='04/21/10' select * from [sheet1$] where LoginDate='04/21/2010' select * from [sheet1$] where LoginDate='04-21-10' select * from [sheet1$] where LoginDate='04-21-2010' select * from [sheet1$] where LoginDate='Apr-21-10' select * from [sheet1$] where LoginDate='Apr-21-2010' select * from [Sheet1$] where [LoginDate] = '"+DateTime.Parse("04-21-10").ToString()+"'" select * from [Sheet1$] where [LoginDate] = '"+DateTime.Parse("04-21-10")+"'" Still I am not getting. Can anyone, pls help me. It's very urgent. Regards, Dileep

                1 Reply Last reply
                0
                • T T M Gray

                  How consistant is the data in your spreadsheet? Do all of the rows have dates in the date column? The Excel database driver determines the datatype of each column by the values in the first 10 rows. If your first ten rows have nothing in the date column or have other text like N/A or -, then that column will not be considered a date and you can't query it like a date.

                  C Offline
                  C Offline
                  cheguri
                  wrote on last edited by
                  #8

                  Thanks friends, I have got it in another way. select * from [sheet1$] where LoginDate=#21/04/10# It's working fine. Thanks everyone. Regards, Dileep.

                  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