One Form with Multiple Tables
I received the following question a few days ago:
“I am trying to use three tables from the same dataset in one form that I am creating in vs.net winforms my problem I guess is the setup of it as I can get them all on the form but cant get them to all post to the separate tables when I click save I am using a mysql database with the Mysql connector not the obdc can this even be done?”
Frustrating, isn’t it? .NET makes some things SO easy, and then when it isn’t you figure you must have done something wrong.
The good news is, your problem probably has nothing to do with using mySQL–it is all in how you are using the database stuff in WinForms.
I actually had to go digging for some old code to find some samples, but here is your basic problem.
The wizardy stuff in .NET only really works with one table at a time. Once you put multiple tables on a form you have to go in and wire up stuff on your own.
If you check your Save button’s click event, you will probably see code that looks something like this:
private void formBindingNavigatorSaveItem_Click (object sender, EventArgs e) { this.Validate(); this.driversBindingSource.EndEdit(); this.tableAdapterManager .UpdateAll(this.socialSubmitterDataSet); }
But when you put in multiple tables, you end up with multiple BindingSources, so you need to add each of those in with the EndEdit() call and then call UpdateAll() once they’ve all been closed out.
private void formBindingNavigatorSaveItem_Click (object sender, EventArgs e) { this.Validate(); this.dataOneBindingSource.EndEdit(); fKdataOneDataTwoBindingSource.EndEdit(); fKdataOneDataThreeBindingSource.EndEdit(); dataFourBindingSource.EndEdit(); this.tableAdapterManager .UpdateAll(this.socialSubmitterDataSet); }
Notice that some of the BindingSources are actually foreign keys. It will depend on how you have your datasets wired in to your form, but the most likely scenario is that you have foreign keys that you are bound to that are pointing to the tables. This is what allows you to move your cursor in to a new row in a master table and have the child tables automatically update to show the children.
Other post in winforms
- WinForms - Database Changes not sticking. - April 28th, 2008
- Windows Forms - Passing Parameters at Runtime - March 9th, 2009
- WinForms - Change The Active Tab - March 30th, 2009
- VB.NET Processing Before WinForm Display - August 6th, 2009
- One Form with Multiple Tables - March 24th, 2010
Other Related Items:
Over Bed TableEasily assembled, over bed table with wood grain laminated top measures 30" x 15". Height adjusts from 28" to 45".
Butterfly 808 II Table Tennis ShoesLightweight shoes with tacky rubber soles
High Fashion Dress Form 5ft Lifesize Wire MannequinThis lady form wire mannequin is new to the marketplace. These have been used by interior designers for display in homes, in the master bedroom suite,... Read More >









