المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Saving changed data from a BindingSource



C# Programming
06-11-2011, 04:12 AM
I have a C# 2010 Windows Forms project that accesses (primarily) two tables in a SQL Server 2008 database. Each table is accessed in two modes: active accounts and cancelled accounts, and both have to be visible and editable at the same time (user requirement). The way I have it set up now is to have one DataSet, one TableAdapterManager, two TableAdapters (one for each table) and four BindingSources (two for each table adapter; one for active, one for cancelled). I have FillBy/GetDataBy methods setup for each TableAdapter that fill my BindingSources correctly. This is the code I’m using for filling them:
htcActiveBindingSource.DataSource = this.htcTableAdapter.ActiveGetDataBy(gpn);htcCancelledBindingSource.DataSource = this.htcTableAdapter.CancelledGetDataBy(gpn);vetActiveBindingSource.DataSource = this.vetTableAdapter.ActiveGetDataBy(gpn);vetCancelledBindingSource.DataSource = this.vetTableAdapter.CancelledGetDataBy(gpn);Everything works exactly as I was hoping, except for saving. The code I was using for saving is this:
this.Validate();this.htcActiveBindingSource.EndEdit();this.htcCancelledBindingSource.EndEdit();this. vetActiveBindingSource.EndEdit();this.vetCancelledBindingSource.EndEdit();this.tableAdapterManager.U pdateAll(this.cramdDataSet);When I step through in debug mode, the current row in the BindingSource knows that it has been modified after the EndEdits run. However, when it executes the UpdateAll, nothing happens in the database. Playing around with it, I figured out that if I fill the TableAdapter directly, like this:
this.htcTableAdapter.ActiveFillBy(this.cramdDataSet.htc, gpn);then it works, but only for just active or just cancelled, not both at the same time (it sets both binding sources to the same data). Is there some way to get the data from the independent BindingSources back into the TableAdapter? Or am I going to be forced to create a second table adapter for the cancelled versions of each table? Am I going about this in a completely retarded way? If so, please enlighten me! (As much as I’d like to make my code work, I’m not opposed to rewriting big chunks to do it the “right” way.) I’m also going to need to insert new records created from the form, but I haven’t gotten to that point yet since my basic save is not even working.

Thanks in advance!