[2005] Fill a datatable with the contents of 3 other data tables
Hello,
I have one data table with fields SerialNo, manufacturer, and model. Called AllParts.
I have 3 other data tables (software, components, equipment) that have those same fields plus some extra fields.
I want to fill this allParts with the serialNo, manufacturer, and model from the other tables.
So allParts will contain rows from software, components, equipment
a bit like copying all the contents from the 3 tables and merging them into a single data table called allParts.
Can anyone help me with this.
Many thanks,
Steve
Re: [2005] Fill a datatable with the contents of 3 other data tables
Just loop through the rows of a source table and call the LoadDataRow method of the destination table. Do that three times and you're done.
Re: [2005] Fill a datatable with the contents of 3 other data tables
Hello,
Not sure which method is better but I did it this way.
Code:
dtAllCustomerPart.Merge(dtCustomersSoftware)
dtAllCustomerPart.Merge(dtCustomersComponents)
dtAllCustomerPart.Merge(dtCustomersEquipment)
Thanks for any advice on this,
Re: [2005] Fill a datatable with the contents of 3 other data tables
No advice just a question if you don't mind (I'm learning this and need to do something similar).
Did you create 3 new datasets and merge them into a summary dataset? Or are they tables? I'm confused by all this and am just trying to get it straight in my head. :thumb:
Re: [2005] Fill a datatable with the contents of 3 other data tables
Quote:
Originally Posted by steve_rm
Hello,
Not sure which method is better but I did it this way.
Code:
dtAllCustomerPart.Merge(dtCustomersSoftware)
dtAllCustomerPart.Merge(dtCustomersComponents)
dtAllCustomerPart.Merge(dtCustomersEquipment)
Thanks for any advice on this,
If that works then that would definitely be a better way. I wasn't aware that you could merge tables with different schema. I guess just the corresponding columns are used and the rest are ignored.
Re: [2005] Fill a datatable with the contents of 3 other data tables
Hello Stimbo,
I used 1 dataset and 4 data tables. The dataset can hold many data tables.
I merged 3 data tables into 1 datatable.
Hope this helps,
Steve