943,865 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1088
  • VB.NET RSS
May 29th, 2008
0

Saving changes in a master table

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
roblespaulo is offline Offline
2 posts
since May 2008
Jun 4th, 2008
0

Re: Saving changes in a master table

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.
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 4th, 2008
0

Re: Saving changes in a master table

Click to Expand / Collapse  Quote originally posted by dadelsen ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
roblespaulo is offline Offline
2 posts
since May 2008
Jun 5th, 2008
0

Re: Saving changes in a master table

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:

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  2. Try
  3.  
  4. ' DEBUG: catch errors of command builder
  5. 'Dim XCmd As New OleDb.OleDbCommandBuilder(DA)
  6.  
  7. ' check state of tables and dataadapter
  8. Try
  9. Dim XCmd As New OleDb.OleDbCommandBuilder(DA)
  10. For Each aTbl As System.Data.DataTable In DS.Tables
  11. Dim aChgTbl As DataTable = aTbl.GetChanges
  12. If aChgTbl Is Nothing Then
  13. Console.WriteLine("Table: {0} Changed: nothing", aTbl.TableName)
  14. Else
  15. Console.WriteLine("Table: {0} Changed: {1} Rows", aTbl.TableName, aChgTbl.Rows.Count)
  16. End If
  17. Next
  18. Console.WriteLine("Insert: {0}", DA.InsertCommand.CommandText)
  19. Console.WriteLine("Update: {0}", DA.UpdateCommand.CommandText)
  20. Console.WriteLine("Delete: {0}", DA.DeleteCommand.CommandText)
  21. Catch ex As Exception
  22. Console.WriteLine("{0}", ex.ToString)
  23. End Try
  24. ' END DEBUG
  25.  
  26. 'DS.AcceptChanges()
  27. DS.GetChanges()
  28. DA.Update(DS)
  29. Console.WriteLine(DA.UpdateCommand.CommandText)
  30. MessageBox.Show("Saved", "ESP MESSAGES", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  31. Catch
  32. MessageBox.Show("Please check basic information has been typed, " & Chr(13) & "Partner, FORModel, JITModel, PionnerModel, and PlantCode")
  33. 'DS.RejectChanges()
  34. End Try
  35. End Sub
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Versioning & Deploying Core Libraries
Next Thread in VB.NET Forum Timeline: [ask] how to put image into textbox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC