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. Adding dates to a database

Adding dates to a database

Scheduled Pinned Locked Moved Web Development
helpdatabase
4 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.
  • X Offline
    X Offline
    Xavier Shay
    wrote on last edited by
    #1

    I'm trying to create a forums site, and I would like to add a date to all posts. At the moment I have the following code: SQLStmt = "INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) " SQLStmt = SQLStmt & " VALUES (" & forumID & ", " & parentID & ", " & userID & ", '" & subject & "', '" & message & "', #" & Date() & "#)" set RS = conn.Execute(SQLStmt) Which when expanded prints something like: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', #2/14/2002#) This all works fine if I exclude the Date Field. The most descriptive error I get is: Microsoft JET Database Engine (0x80040E14) Syntax error in INSERT INTO statement. Any help would be greatly appreciated - X

    K 1 Reply Last reply
    0
    • X Xavier Shay

      I'm trying to create a forums site, and I would like to add a date to all posts. At the moment I have the following code: SQLStmt = "INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) " SQLStmt = SQLStmt & " VALUES (" & forumID & ", " & parentID & ", " & userID & ", '" & subject & "', '" & message & "', #" & Date() & "#)" set RS = conn.Execute(SQLStmt) Which when expanded prints something like: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', #2/14/2002#) This all works fine if I exclude the Date Field. The most descriptive error I get is: Microsoft JET Database Engine (0x80040E14) Syntax error in INSERT INTO statement. Any help would be greatly appreciated - X

      K Offline
      K Offline
      Konstantin Vasserman
      wrote on last edited by
      #2

      I think you need to replace # signs with '. For example: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', '2/14/2002')

      X 1 Reply Last reply
      0
      • K Konstantin Vasserman

        I think you need to replace # signs with '. For example: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', '2/14/2002')

        X Offline
        X Offline
        Xavier Shay
        wrote on last edited by
        #3

        I'm afraid that didn't work. But, Alas! I found the solution! I changed the 'Date' field to 'DatePosted'. I presume 'Date' is a reserved word. It took me three hours to figure that out. Oh well. Thanks for you help anyway - X

        L 1 Reply Last reply
        0
        • X Xavier Shay

          I'm afraid that didn't work. But, Alas! I found the solution! I changed the 'Date' field to 'DatePosted'. I presume 'Date' is a reserved word. It took me three hours to figure that out. Oh well. Thanks for you help anyway - X

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yup .. your right Date is a preserve word ... but by adding brackets [] it will work also like this [Date] . Sometimes I use it when I have a field contain 2 words like [Date Posted]

          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