I have the code below in VS 2012. It dynamically allocates a DataGridView and an Update button, then it binds the grid to MS Access database table. That all works well. When I click the Update button btnUpdate_Click() is called, which calls the DataAdapter's Update() method. That produces the syntax error and then displays the sql string for debugging only. Anyone know what I'm missing?
'*********************************************************
'The following are globals at the top of the program
'*********************************************************
Dim con As New OleDb.OleDbConnection
Dim nTries As Integer = 0
Dim binding_source As BindingSource
Dim data_table As DataTable
Dim data_adapter As OleDb.OleDbDataAdapter
Dim cmd_builder As OleDb.OleDbCommandBuilder
'*********************************************************
Private Sub UsersToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UsersToolStripMenuItem.Click
Dim btnUpdate As System.Windows.Forms.Button
Dim sql As String
'Dim ds As New DataSet
Dim dg As System.Windows.Forms.DataGridView = AddControl(New System.Windows.Forms.DataGridView, 40, 40, 345)
binding_source = New BindingSource()
data_table = New DataTable()
sql = "SELECT [LoginName],[Password] FROM [Users]"
dg.DataSource = binding_source
data_adapter = New OleDb.OleDbDataAdapter(sql, con)
cmd_builder = New OleDb.OleDbCommandBuilder(data_adapter)
data_adapter.Fill(data_table)
binding_source.DataSource = data_table
btnUpdate = AddControl(New System.Windows.Forms.Button, 75, 220, Nothing)
btnUpdate.Text = "Update"
'btnAdd.AutoSize = True
AddHandler btnUpdate.Click, AddressOf Me.btnUpdate_Click
End Sub
'*********************************************************
' Problem is here
'*********************************************************
Private Sub btnUpdate_Click(sender As Object, e As EventArgs)
Try
data_adapter.Update(CType(binding_source.DataSource, DataTable))
Catch ex As OleDbException
MsgBox("ERROR:" & ex.Source & " " & ex.Message, MsgBoxStyle.OkOnly)
MsgBox(cmd_builder.GetInsertCommand().CommandText, MsgBoxStyle.OkOnly)
End Try
End Sub