DatagridView , set datasource from 2 or more related tables
-
In DatagridView , is possible to set as datasource 2 or more related tables from a dataset ? And more , to use a Sum of a field as datagridview column ? For illustration i have 2 tables in my dataset: Table 1 : St_ID (primary key ) , Name Table 2 : MID ( Primary Key) , Student (related with ST_ID) , QTy , Date in table 2 for a student there are 1 or multiple registration with different QTY and Date. Now i want to display in datagridview 2 columns : Name Sum(QTY) But i don't want to query directly the database , but i want to use only tables in dataset. Thank you !
-
In DatagridView , is possible to set as datasource 2 or more related tables from a dataset ? And more , to use a Sum of a field as datagridview column ? For illustration i have 2 tables in my dataset: Table 1 : St_ID (primary key ) , Name Table 2 : MID ( Primary Key) , Student (related with ST_ID) , QTy , Date in table 2 for a student there are 1 or multiple registration with different QTY and Date. Now i want to display in datagridview 2 columns : Name Sum(QTY) But i don't want to query directly the database , but i want to use only tables in dataset. Thank you !
The DataSet class doesn't have a Select method to allow you to do this easily. If your DataSet, which is a collection of DataTable and DataRelation objects, has those relationship objects in it, you can build your own table by enumerating the Name records in the "Table1" table, and lookup up the keys in the "Table2" table. You'd be able to interate over those records to build the Sum you want, then just add the Name and Sum to the DataTable you're building. Or, you can simplify this greatly by having the database do it and just hand to you table, just like the SELECT commands you executed to get these tables in the first place.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007