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. Wrong syntax when trying to save CSV file column as string

Wrong syntax when trying to save CSV file column as string

Scheduled Pinned Locked Moved ASP.NET
helpdatabasejson
8 Posts 3 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.
  • J Offline
    J Offline
    jebin k
    wrote on last edited by
    #1

    Hi, I am parsing a CSV file and storing it in database. All the table fields are varchar. The CSV file has a column called Date which is in the format 11/11/2007 where i checked the Format Cells it displays date. The problem is when i save this field in the database it automatically saves as 11/11/2007 12:00:00 AM. I need not want to the time to get saved. Can any one please help me out.

    N G 2 Replies Last reply
    0
    • J jebin k

      Hi, I am parsing a CSV file and storing it in database. All the table fields are varchar. The CSV file has a column called Date which is in the format 11/11/2007 where i checked the Format Cells it displays date. The problem is when i save this field in the database it automatically saves as 11/11/2007 12:00:00 AM. I need not want to the time to get saved. Can any one please help me out.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      You might be using a DateTime/Smalldatetime data type. It always append time with it. Try using varchar instead.


      My Website | Ask smart questions

      J 1 Reply Last reply
      0
      • N N a v a n e e t h

        You might be using a DateTime/Smalldatetime data type. It always append time with it. Try using varchar instead.


        My Website | Ask smart questions

        J Offline
        J Offline
        jebin k
        wrote on last edited by
        #3

        No i am using varchar datatype only.

        J 1 Reply Last reply
        0
        • J jebin k

          No i am using varchar datatype only.

          J Offline
          J Offline
          jebin k
          wrote on last edited by
          #4

          Instead of storing in the database, i displayed in the grid it shows the same with Time.

          N 1 Reply Last reply
          0
          • J jebin k

            Instead of storing in the database, i displayed in the grid it shows the same with Time.

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            Are you reading this columns value through a datetime variable in page ?


            My Website | Ask smart questions

            J 1 Reply Last reply
            0
            • N N a v a n e e t h

              Are you reading this columns value through a datetime variable in page ?


              My Website | Ask smart questions

              J Offline
              J Offline
              jebin k
              wrote on last edited by
              #6

              This is what i do string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\\\""; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(ConStr); System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("Select * from " + file, conn); da.Fill(ds, "TextFile"); DGCsv.DataSource = ds.Tables[0].DefaultView;

              1 Reply Last reply
              0
              • J jebin k

                Hi, I am parsing a CSV file and storing it in database. All the table fields are varchar. The CSV file has a column called Date which is in the format 11/11/2007 where i checked the Format Cells it displays date. The problem is when i save this field in the database it automatically saves as 11/11/2007 12:00:00 AM. I need not want to the time to get saved. Can any one please help me out.

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                A DataTime value always has a date and a time component. If you don't specify the time component, it becomes zero (or 12:00 AM). You should change the data type of the database field into datetime, if you store the date as text you can't work with the value. WHen you display the value, you just format it the way that you want it.

                --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

                J 1 Reply Last reply
                0
                • G Guffa

                  A DataTime value always has a date and a time component. If you don't specify the time component, it becomes zero (or 12:00 AM). You should change the data type of the database field into datetime, if you store the date as text you can't work with the value. WHen you display the value, you just format it the way that you want it.

                  --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

                  J Offline
                  J Offline
                  jebin k
                  wrote on last edited by
                  #8

                  I have Varchar as my datatype, I checked CSV File in that Date column i found in the Format cells that the column is defined as Date. I think that may the problem , this is the code i use string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\\\""; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(ConStr); System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("Select * from " + file, conn); da.Fill(ds, "TextFile"); DGCsv.DataSource = ds.Tables[0].DefaultView;

                  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