| | |
Updating multiple tables in C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2006
Posts: 1
Reputation:
Solved Threads: 0
I am trying to update two related tables, so I created the code below. However, when the program runs the information is not updated to the DB and a message saying update unsucessful appears.
Please could you help me, what am I doing wrong?
Please could you help me, what am I doing wrong?
private void saveToolStripButton_Click(object sender, EventArgs e) { UpdateData(); } private void UpdateData() { this.Validate(); this.newspaperDeliverysBindingSource1.EndEdit(); this.customersBindingSource.EndEdit(); using (System.Transactions.TransactionScope updateTransaction = new System.Transactions.TransactionScope()) { try { DeleteNewspaperDeliverys(); DeleteCustomers(); AddNewCustomers(); AddNewNewspaperDeliverys(); updateTransaction.Complete(); managementDataSet.AcceptChanges(); } catch (TransactionAbortedException ex) { MessageBox.Show("Update unsuccessful"); } } } private void DeleteNewspaperDeliverys() { managementDataSet.NewspaperDeliverysDataTable deletedChildRecords; deletedChildRecords = (managementDataSet.NewspaperDeliverysDataTable) managementDataSet.NewspaperDeliverys.GetChanges(DataRowState.Deleted); // Remove all deleted orders from the newspaper deliverys table if (deletedChildRecords != null) { try { newspaperDeliverysTableAdapter.Update(deletedChildRecords); } catch (Exception ex) { MessageBox.Show("Delete Newspaper Delivery Failed"); } } } private void DeleteCustomers() { managementDataSet.CustomersDataTable deletedCustomers; deletedCustomers = (managementDataSet.CustomersDataTable) managementDataSet.Customers.GetChanges(DataRowState.Deleted); if (deletedCustomers != null) { try { // Update the Customers table. customersTableAdapter.Update(deletedCustomers); MessageBox.Show("Customer permanently deleted"); } catch (System.Exception ex) { MessageBox.Show("Delete Customer Failed"); } } } private void AddNewCustomers() { managementDataSet.CustomersDataTable newCustomers; newCustomers = (managementDataSet.CustomersDataTable) managementDataSet.Customers.GetChanges(DataRowState.Added); if (newCustomers != null) { try { // Update the Customers table. customersTableAdapter.Update(newCustomers); } catch (Exception ex) { MessageBox.Show("Add New Customer Failed"); } } } private void AddNewNewspaperDeliverys() { managementDataSet.NewspaperDeliverysDataTable newChildRecords; newChildRecords = (managementDataSet.NewspaperDeliverysDataTable) managementDataSet.NewspaperDeliverys.GetChanges(DataRowState.Added); if (newChildRecords != null) { try { newspaperDeliverysTableAdapter.Update(newChildRecords); } catch (Exception ex) { MessageBox.Show("Add New Order Failed"); } } }
Last edited by alc6379; Apr 29th, 2006 at 12:28 am.
![]() |
Similar Threads
- Searching for a record in multiple tables (VB.NET)
- updating multiple tables (ASP)
- Multiple Tables in a Database (Visual Basic 4 / 5 / 6)
- Delete from multiple tables (MySQL)
- Query multiple tables? (MySQL)
- updating 2 HTML tables on one PHP page (PHP)
Other Threads in the C# Forum
- Previous Thread: XmlTextReader.ReadBase64
- Next Thread: c# or vb.net - how earn more?
| Thread Tools | Search this Thread |
.net access algorithm array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml





