But if the DA has the commands, why do you call the Command Builder?
In order to check why the DA cannot save DS's changes to the DB, I would try to find out
- which of the tables in the dataset actually have changes
- if the DA after calling the command builder has all needed commands, or any errors caused by the command builder.
For example:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
' DEBUG: catch errors of command builder
'Dim XCmd As New OleDb.OleDbCommandBuilder(DA)
' check state of tables and dataadapter
Try
Dim XCmd As New OleDb.OleDbCommandBuilder(DA)
For Each aTbl As System.Data.DataTable In DS.Tables
Dim aChgTbl As DataTable = aTbl.GetChanges
If aChgTbl Is Nothing Then
Console.WriteLine("Table: {0} Changed: nothing", aTbl.TableName)
Else
Console.WriteLine("Table: {0} Changed: {1} Rows", aTbl.TableName, aChgTbl.Rows.Count)
End If
Next
Console.WriteLine("Insert: {0}", DA.InsertCommand.CommandText)
Console.WriteLine("Update: {0}", DA.UpdateCommand.CommandText)
Console.WriteLine("Delete: {0}", DA.DeleteCommand.CommandText)
Catch ex As Exception
Console.WriteLine("{0}", ex.ToString)
End Try
' END DEBUG
'DS.AcceptChanges()
DS.GetChanges()
DA.Update(DS)
Console.WriteLine(DA.UpdateCommand.CommandText)
MessageBox.Show("Saved", "ESP MESSAGES", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Catch
MessageBox.Show("Please check basic information has been typed, " & Chr(13) & "Partner, FORModel, JITModel, PionnerModel, and PlantCode")
'DS.RejectChanges()
End Try
End Sub