1

I am connecting to a Access DB, with following Conn String

Conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=\\server\share\Data\PFWTRAN.MDB"

The following SQL works fine;

SQLIn =     "SELECT Date, Time " & _
            "FROM Transactions " & _
            "WHERE TokenNumber = " & TokenNo & " " & _
            "AND Date >= " & FromDateG & " " & _
            "AND Direction = -1 " & _               
            "ORDER BY Date, TransactionNumber;"

However, I want rows where Transactions.Exception = 0, yet when I add this AND condition, the script fails when the RS is opened;

error '80004005' /path/.../.../...asp, line 97

If I remove the AND condition, it works again.

Even If I try and put 'Exception' in the SELECT section, it won't run and gives me that error.

Why would the inclusion of one field cause such an error? I read the error is due to permissions, but my permissions are fine as the SQL works without this one field in it.

Any clues?

It is a very old Access 95 database (or even earlier), perhaps I need to change connection provided?

4

1 回答 1

1

但是,我想要 Transaction.Exception = 0 的行,但是当我添加此 AND 条件时,打开 RS 时脚本失败

但是 Transaction.Exception 指的是与您的查询使用的表不同的表。

FROM Transactions

Date,TimeException是A​​ccess 中的问题名称和保留字。将这些名称括在方括号中,或在它们前面加上表名/别名。

考虑切换您的方法以使用参数查询......并将其TokenNoFromDateG值作为参数提供,而不是将它们的值构建到SELECT语句中。

于 2012-08-09T14:59:39.633 回答