Hi, im doing a software that uses diferent tables, and im trying to implement a save button but it doesnt save anything.

This is the code.

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
Dim XCmd As New OleDb.OleDbCommandBuilder(DA)
'DS.AcceptChanges()
DS.GetChanges()
DA.Update(DS)
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

After instantiation of the command builder: do the Commandtext properties of DA.UpdateCommand, DA.InsertCommand and DA.DeleteCommand contain the required SQL commands?
P.S.: DS.GetChanges produces a copy that contains the changed rows. The code does not use this subset but the original dataset. But unless AcceptChanges is called, it should also work with the original dataset.

After instantiation of the command builder: do the Commandtext properties of DA.UpdateCommand, DA.InsertCommand and DA.DeleteCommand contain the required SQL commands?
P.S.: DS.GetChanges produces a copy that contains the changed rows. The code does not use this subset but the original dataset. But unless AcceptChanges is called, it should also work with the original dataset.

Well the SQL has the commands because i have an other app that does save using similar code

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.