So, I have successfully filled a DataGridView with the contents of a table from an Access database.
My problem is that when I try to use the DataAdapter's Update() method to save the changes made in the DataGridView to the database, I always get OleDbExceptions.
For example, if I insert a new row, I get OleDbException "Syntax error in INSERT INTO command". If I change an existing value in the DataGridView, it gives me the 'Syntax error in UPDATE command'.
What am I doing wrong? Here is the code that I have that reads the database into my datagrid.
And again, I get these exceptions whenever I try to use the DataAdapter.Update() method, ie
Any help would be greatly appreciated!
My problem is that when I try to use the DataAdapter's Update() method to save the changes made in the DataGridView to the database, I always get OleDbExceptions.
For example, if I insert a new row, I get OleDbException "Syntax error in INSERT INTO command". If I change an existing value in the DataGridView, it gives me the 'Syntax error in UPDATE command'.
What am I doing wrong? Here is the code that I have that reads the database into my datagrid.
VB.NET:
da as DataAdapter
table as DataTable
ds as DataSet
bs as BindingSource
cmdb as OleDbCommandBuilder
Public Sub fillUserTable()
Dim query As String = "SELECT * FROM [User]"
GetData(query)
frmUserTable.DataGridView1.DataSource = bs
End Sub
Private Sub GetData(ByVal selectCommand As String)
Try
' Create a new data adapter based on the specified query.
Me.da = New OleDbDataAdapter(selectCommand, connString)
' Create a command builder to generate SQL update, insert, and
' delete commands based on selectCommand. These are used to
' update the database.
Me.cmdb = New OleDbCommandBuilder(Me.da)
' Populate a new data table and bind it to the BindingSource.
Me.table = New DataTable()
Me.da.Fill(table)
Me.bs.DataSource = table
Catch ex As OleDbException
MessageBox.Show("OH NOES")
End Try
End Sub
And again, I get these exceptions whenever I try to use the DataAdapter.Update() method, ie
VB.NET:
Me.da.Update(CType(Me.bs.DataSource, DataTable))
Any help would be greatly appreciated!