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# and MS-Access : Inserting or updating datetime

C# and MS-Access : Inserting or updating datetime

Scheduled Pinned Locked Moved C#
csharpdatabaseannouncement
3 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.
  • S Offline
    S Offline
    Sifar 0
    wrote on last edited by
    #1

    Hi all, I have a C# desktop application and I am using MS-Access database. I am using below code for update operation. string SqlString = "UPDATE table_name SET Bdate = @Bdate WHERE SrNo = @SrNo"; OledbCmd = new OleDbCommand(SqlString, OleDbConn); OledbCmd.Parameters.AddWithValue("@SrNo", intSrNo); OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString()); Same approach is used for Insert operation also. All working fine... But I have read in one article that, DateTime should be enclosed withing single quote or #, when you are working with MS-Access. Right now, my code is working fine. Please, explain me if there is any difference between the approach I am using and the approach that I have read.. Thanks,

    Regards, -SIFAR.

    A P 2 Replies Last reply
    0
    • S Sifar 0

      Hi all, I have a C# desktop application and I am using MS-Access database. I am using below code for update operation. string SqlString = "UPDATE table_name SET Bdate = @Bdate WHERE SrNo = @SrNo"; OledbCmd = new OleDbCommand(SqlString, OleDbConn); OledbCmd.Parameters.AddWithValue("@SrNo", intSrNo); OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString()); Same approach is used for Insert operation also. All working fine... But I have read in one article that, DateTime should be enclosed withing single quote or #, when you are working with MS-Access. Right now, my code is working fine. Please, explain me if there is any difference between the approach I am using and the approach that I have read.. Thanks,

      Regards, -SIFAR.

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

      What is the field type of "@Bdate" in the database ? # and quote are date delimiters in MS-Access. The older versions only supported # but the newer version support quotes as well.

      1 Reply Last reply
      0
      • S Sifar 0

        Hi all, I have a C# desktop application and I am using MS-Access database. I am using below code for update operation. string SqlString = "UPDATE table_name SET Bdate = @Bdate WHERE SrNo = @SrNo"; OledbCmd = new OleDbCommand(SqlString, OleDbConn); OledbCmd.Parameters.AddWithValue("@SrNo", intSrNo); OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString()); Same approach is used for Insert operation also. All working fine... But I have read in one article that, DateTime should be enclosed withing single quote or #, when you are working with MS-Access. Right now, my code is working fine. Please, explain me if there is any difference between the approach I am using and the approach that I have read.. Thanks,

        Regards, -SIFAR.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        If Bdate is a date then don't call ToSTring() when setting the parameter OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString());

        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