An unhandled exception of type 'system.data.oledb.oledbexception'

571 views Asked by At

I'm using Visual Basic.net 2013. When I click the button to save the record this is the error that I'm getting and the error points me to

da.Update(ds, "wyn")

I'm using microsoft access as the database

Error Message:

an unhandled exception of type 'system.data.oledb.oledbexception' occured in system.data.dll additional information: syntax error in insert into statement

This is the source code of that button:

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.")
1

There are 1 answers

0
jmcilhinney On

This error usually occurs as the result of using a column name that is a reserved word or contains spaces or other special characters. The best option is to avoid such column names in the first place. If that's not an option then tell your command builder to quote identifiers. As your database is Access, add this:

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

That will wrap all column names in the generated SQL code in those brackets and prevent reserved words or special characters causing syntax errors.