VB Code:
  1. Private myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Path ' Put here the connection string
  2.     Private myConnection As New OleDbConnection(myConnString) 'Create a new connection
  3.  
  4.     Public Function GetDataAdapter(ByVal Query As String) As OleDbDataAdapter
  5.         Dim DA As New OleDbDataAdapter(Query, myConnection)
  6.         Return DA
  7.     End Function
  8.     Public Function ExecuteUpdate(ByRef DA As OleDbDataAdapter, ByRef DS As DataSet, ByRef table As String) As Boolean
  9.         Dim CB As New OleDb.OleDbCommandBuilder(DA)
  10.  
  11.         DA.UpdateCommand = CB.GetUpdateCommand
  12.  
  13.         Try
  14.             DA.Update(DS, table)
  15.             Return True
  16.         Catch e As Exception
  17.             MsgBox(e.ToString)
  18.             Return False
  19.         End Try
  20.     End Function
This is the code I have in my project.
The problem is (again) I can't update the database... In a form I write:
VB Code:
  1. dim DB as new Databaseclass ' this is the class of the above code
  2. dim DA as OleDbDataAdapter
  3. dim DS as new DataSet()
  4.  
  5. DA=DB.GetDataAdapter("SELECT * FROM mytable") ' Get the Dataadapter
  6. DA.Fill(DS,"mytable") ' Fill the DataSet
  7. DS.Tables(0).Rows(0)(0)="kk" ' Just modify an element
  8. dim CB as New OleDbCommandBuilder(DA)
  9.  
  10. 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.
What is this ??!?!?