VB Code:
Private myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Path ' Put here the connection string
Private myConnection As New OleDbConnection(myConnString) 'Create a new connection
Public Function GetDataAdapter(ByVal Query As String) As OleDbDataAdapter
Dim DA As New OleDbDataAdapter(Query, myConnection)
Return DA
End Function
Public Function ExecuteUpdate(ByRef DA As OleDbDataAdapter, ByRef DS As DataSet, ByRef table As String) As Boolean
Dim CB As New OleDb.OleDbCommandBuilder(DA)
DA.UpdateCommand = CB.GetUpdateCommand
Try
DA.Update(DS, table)
Return True
Catch e As Exception
MsgBox(e.ToString)
Return False
End Try
End Function
This is the code I have in my project.
VB Code:
dim DB as new Databaseclass ' this is the class of the above code
dim DA as OleDbDataAdapter
dim DS as new DataSet()
DA=DB.GetDataAdapter("SELECT * FROM mytable") ' Get the Dataadapter
DA.Fill(DS,"mytable") ' Fill the DataSet
DS.Tables(0).Rows(0)(0)="kk" ' Just modify an element
dim CB as New OleDbCommandBuilder(DA)
DA.UpDate(DS,"mytable") ' Update with changes, BUT here I get the error.
The error says there's an error in the UPDATE instruction, but I'm sure it's right!!! The error is the same when I call DB.ExecuteUpdate(....). But if I put all the code in the DB class (load dataadapter, fill dataset, modify, update) I Update the DB regularly.