1

以下代码因此错误而崩溃:

System.Data.OleDb.OleDbException:'参数太少。预计 1'

Dim selectString As String = "SELECT * FROM Products WHERE id = ?;"
Dim cmd As OleDbCommand = New OleDbCommand(selectString, dbOleDB)
cmd.Parameters.AddWithValue("ID", id)
Dim reader As OleDbDataReader = cmd.ExecuteReader()

如果我对 Access 数据库引擎安装进行修复,则错误会消失一天。
同样的事情发生在多台运行不同版本 Windows 的机器上。
这个问题开始于大约 2 周前。

有人知道发生了什么吗?

4

1 回答 1

0

OleDbCommand 对命名参数的行为不正确。

试试这个,

Dim selectString As String = "SELECT * FROM Products WHERE id = ?;"
Dim cmd As OleDbCommand = New OleDbCommand(selectString, dbOleDB)
cmd.Parameters.Add("@ID", OleDbType.BigInt).Value = id; '@ID essentially means nothing here.  The Adds you make have to be sequential
Dim reader As OleDbDataReader = cmd.ExecuteReader()
于 2020-02-20T20:37:58.677 回答