以下代码因此错误而崩溃:
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的多台计算机上
这个问题大约两周前就开始了。
有人知道发生了什么事吗?
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()