类型为"system.data.oledb.oledbexception"的未处理异常



我使用的是Visual Basic.net 2013。当我点击按钮保存记录时这是我得到的错误错误指向

da.Update(ds, "wyn")

我使用microsoft access作为数据库

错误信息:

类型为"system.data.oledb"的未处理异常。在system.data.dll中发生错误附加信息:insert into语句

语法错误

这是该按钮的源代码:

Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("wyn").NewRow()
dsNewRow.Item("label") = txtLabel.Text
dsNewRow.Item("bcode") = txtBcode.Text
ds.Tables("wyn").Rows.Add(dsNewRow)
da.Update(ds, "wyn")
MsgBox("One record saved.")

通常由于使用保留字或包含空格或其他特殊字符的列名而发生此错误。最好的选择是从一开始就避免使用这样的列名。如果这不是一个选项,那么告诉您的命令生成器引用标识符。由于您的数据库是Access,请添加以下内容:

cb.QuotePrefix = "["
cb.QuoteSuffix = "]"

将生成的SQL代码中的所有列名包装在括号中,并防止保留词或特殊字符导致语法错误。

相关内容

最新更新