| | |
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 |
.net .net2008 2008 access account advanced application array basic beginner browser button buttons center click code combo cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms generatetags gridview html images input insert intel internet listview map mobile module monitor msaccess net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





