0

我之前已经从 ASP 将日期输入到 Access 中,并且我使用相同的代码......但无论如何它都不会接受查询。我已经工作了一整天,也许我只是累了,但是有人可以帮我看看这个吗?

这是代码生成的示例查询:

INSERT INTO COMMENTS (FID,AUTHOR,DATE,COMMENT) VALUES ("6","John Doe",#4/15/2012#,"test comment") 

就像我说的,代码的模板直接来自其他有效的地方。如果我从查询中删除日期,它工作正常。我已经三重检查了 DATE 字段是一个 DATE/TIME 列,并且我尝试删除并重新创建它,但没有成功。

将不胜感激一些帮助。

4

3 回答 3

1

我有一段时间没有接触 Access,但您可以尝试一些查询:

查询 1:更改DATE[DATE]sinceDATE可能是 Access 使用的常用关键字。

    INSERT INTO COMMENTS 
    (FID,AUTHOR,[DATE],COMMENT) 
    VALUES 
    ("6","John Doe",#4/15/2012#,"test comment") 

查询 2:更改#4/15/2012#GetDate()(日期戳)

    INSERT INTO COMMENTS 
    (FID,AUTHOR,[DATE],COMMENT) 
    VALUES 
    ("6","John Doe",GETDATE(),"test comment") 

或者也许尝试它们的组合。如果其中任何一个不起作用,请报告。

于 2012-04-15T06:53:33.357 回答
0

你可以试试#MM-DD-YYYY#。还建议使用YYYY-MM-DD,所以你可以尝试#YYYY-MM-DD#甚至#'YYYY-MM-DD'#.

于 2012-04-15T07:49:01.370 回答
0

Here's what I got to work for me:

    strDSNPath = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb")
    strSQL_Insert = "INSERT INTO COMMENTS (FID,AUTHOR,CDATE,COMMENT) VALUES ('6','John Doe','4/15/2012','test comment')"

   Set Conn=Server.CreateObject("ADODB.Connection")
        Conn.Open strDSNPath
            Conn.Execute strSQL_Insert
        Conn.Close
    Set Conn = Nothing

And here's the database: Download

Notes:

*I couldn't get it to work with the (") so I used (')

*The date has no hashtag (which may need fixing)

*Sorry it's so late, it took me like an hour and a half to figure it out, and it only ended up being "use single quotes"

于 2012-04-15T07:57:44.563 回答