Saving changes in a master table

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 2
Reputation: roblespaulo is an unknown quantity at this point 
Solved Threads: 0
roblespaulo roblespaulo is offline Offline
Newbie Poster

Saving changes in a master table

 
0
  #1
May 29th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Saving changes in a master table

 
0
  #2
Jun 4th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 2
Reputation: roblespaulo is an unknown quantity at this point 
Solved Threads: 0
roblespaulo roblespaulo is offline Offline
Newbie Poster

Re: Saving changes in a master table

 
0
  #3
Jun 4th, 2008
Originally Posted by dadelsen View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Saving changes in a master table

 
0
  #4
Jun 5th, 2008
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:

  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC