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. question

question

Scheduled Pinned Locked Moved C#
databasequestioncsharpsql-serversysadmin
4 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.
  • E Offline
    E Offline
    eyalso
    wrote on last edited by
    #1

    i need example in C# + SQL SERVER i want to insert into the DB date and time for example 12/15/2005 and time 10:05 AM how can i define the sqlcommand and lets say in the DB table test i have the colum d as datetime and t as timestamp eyalso

    A G 2 Replies Last reply
    0
    • E eyalso

      i need example in C# + SQL SERVER i want to insert into the DB date and time for example 12/15/2005 and time 10:05 AM how can i define the sqlcommand and lets say in the DB table test i have the colum d as datetime and t as timestamp eyalso

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

      string ins = "insert into table values('" + "2005.12.15 10:05 AM" + "')" SqlDataAdapter da= new SqlDataAdapter (ins,SqlConnection); replace DateTime with varchar ur column in ur table Regards -- modified at 4:51 Thursday 15th December, 2005

      J 1 Reply Last reply
      0
      • A albCode

        string ins = "insert into table values('" + "2005.12.15 10:05 AM" + "')" SqlDataAdapter da= new SqlDataAdapter (ins,SqlConnection); replace DateTime with varchar ur column in ur table Regards -- modified at 4:51 Thursday 15th December, 2005

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        seferi wrote:

        replace DateTime with varchar ur column in ur table

        Thats easily the worst advice ive read here! DONT use varchar to store a date! Also, to THE OP - Timestamp is a special type of binary column, and is not used to store time as the name does imply. To store date and time just create a Date column, which will store a date and time perfectly. Remember to use parameterized queries (for dates especially as the command will take care of inserting the date correctly)

        1 Reply Last reply
        0
        • E eyalso

          i need example in C# + SQL SERVER i want to insert into the DB date and time for example 12/15/2005 and time 10:05 AM how can i define the sqlcommand and lets say in the DB table test i have the colum d as datetime and t as timestamp eyalso

          G Offline
          G Offline
          Gilad Kapelushnik
          wrote on last edited by
          #4

          Instead of storing a DateTime variable store a long (8 byte). convert the DateTime variable to a long by: DateTime A = ; long B = DateTime.Ticks; in order to convert the long number back to DateTime do: DateTime AA = DateTime.MinValue + TimeSpan.FromTicks(B); Enjoy Gilad.

          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