Tab control on form data sources for each tab

LabProARW

Well-known member
Joined
Nov 4, 2019
Messages
52
Programming Experience
1-3
Using VS2022. My form has a tab control where each tab is a different type of instrument. There are individual tables in the back end for each respective type of instrument. I have not been able to find information of how to handle the datasets which each tab will need to be bound to. No doubt this is a simple mechanics question. In the case of 3 instrument tables would I need 3 table adapters, 3 datasets.xsd, and 3 binding sources?

Thank you for your patience.
 
As the name suggests, a table adapter relates to a table. If you have three tables then you need three table adapters. A BindingSource sits between a data source and the UI elements it's bound to. Again, if you have three tables as data sources then you need three BindingSources. You definitely don't need three DataSets. Would you create three databases and have one table in each or one database with three tables in it? A DataSet is an in-app representation of a database, just as DataTables are in-app representations of database tables.

If you generate a typed DataSet from a database, the wizard will generate a DataTable and corresponding table adapter for each table in the database. Each of those is a class and it's then up to you to create and use instances of those classes as needed.
 
This may not be as relevant now in 2023, but back in 2003, you also had to pay attention to how much memory each of those data grid views was using while showing 3 different tables across those 3 tabs. A few million rows in each table quickly adds up. Back then, if the developers did want to implement virtual views into the backend data, they would actually just have fake tabs and there was only one data grid view, and only one data table bound to that single data grid view with a lot of finger crossing that the framework would do the right thing to garbage collect unreferenced data, and that the garbage collect wouldn't take too long and freeze the UI.
 
I have not been able to find information of how to handle the datasets which each tab will need to be bound to. No doubt this is a simple mechanics question. In the case of 3 instrument tables would I need 3 table adapters, 3 datasets.xsd, and 3 binding sources?

3 tables in the db would probably be put into a single dataset, as 3 different data tables, and dragged to 3 different tabs from the data sources window. You would end up with 3 datagridview, 1 dataset, 3 binding sources and 3 table adapters

If the tables all have the same structure then they probably shouldn't be 3 tables, they should be 1 with a differentiator column. In this case you would have 1 table, 1 dataset, 1 data table, 1 table adapter with 1 query that takes a parameter that operates on the differentiator column, your form would have 1 dataset instance, 1 table adapter, 3 binding sources, 3 datagridview. The binding sources would probably have a filter..
You could alternatively structure it to do away with the filter such that the form has 3 datasets, 1 tableadapter, 3 binding sources, and 3 datagridviews.. There are other ways to arrange it too, such as ditching the dataset entirely and binding the datagridview data sources to data tables returned from the table adapters GetByXXX in code rather than in the designer
 
Back
Top Bottom