我正在尝试为oledb dataadapter编写更新命令。我遇到过各种各样的错误。我认为我的绊脚石是我无能为力的愚蠢的字段名称。 也许有人可以看到我的错误?
数据库是访问权限 该表有很多列,但我只想更新一列。 列[Transaction Seq]是一个自动编号 要更新的列[代码(IAO)]是文本 - 255长
错误:参数[@Code(IAO)]没有默认值。
我的代码:
oDAtblBound.SelectCommand = New OleDb.OleDbCommand(strSql, oCon)
Dim builder As OleDb.OleDbCommandBuilder = New OleDbCommandBuilder(oDAtblBound)
builder.QuotePrefix = "["
builder.QuoteSuffix = "]"
oDAtblBound.MissingSchemaAction = MissingSchemaAction.AddWithKey
oDAtblBound.Fill(oTables, "tblBound")
cmd = New OleDbCommand("UPDATE tblBound SET [Code (IAO)] = [@Code (IAO)] WHERE [Transaction Seq] = [@Transaction Seq]", oCon)
cmd.Parameters.Add("[Code (IAO)]", OleDbType.Char, 255, "[Code (IAO)]")
parameter = cmd.Parameters.Add("[Transaction Seq]", OleDbType.Char, 255, "[Transaction Seq]")
parameter.SourceVersion = DataRowVersion.Original
oDAtblBound.UpdateCommand = cmd
答案 0 :(得分:1)
将您的代码更改为.....
cmd = New OleDbCommand("UPDATE tblBound SET [Code (IAO)] = @Code_IOA WHERE [Transaction Seq] = @Transaction_Seq", oCon)
cmd.Parameters.Add("Code_IAO", OleDbType.Char, 255, "Code (IAO)")
parameter = cmd.Parameters.Add("Transaction_Seq", OleDbType.Char, 255, "Transaction Seq")
parameter.SourceVersion = DataRowVersion.Original
oDAtblBound.UpdateCommand = cmd