| | |
Saving changes in a master table
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2007
Posts: 22
Reputation:
Solved Threads: 5
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.
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.
•
•
Join Date: May 2008
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Jun 2007
Posts: 22
Reputation:
Solved Threads: 5
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:
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)
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
![]() |
Similar Threads
- Identifying Drivers needed (Windows 95 / 98 / Me)
Other Threads in the VB.NET Forum
- Previous Thread: Versioning & Deploying Core Libraries
- Next Thread: [ask] how to put image into textbox
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access arithmetic array assignment basic binary bing box button buttons center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel file-dialog firewall folder ftp google hardcopy image images isnumericfuntioncall listview login math memory mobile ms mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record reports" save savedialog searchbox serial soap sorting string tcp temp text textbox timer toolbox trim updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf





