Filter 2 datatables in dataset
-
Hi I have a dataset with 2 datatables, I want to filter/compare the 2 tables and get results in way like Datatable1 ------------------ ID | Name ------------------ 1 XYZ 2 ZZZ Datatable 2 ------------------ ID | Name ------------------ 0 XYZ 0 ZZZ 0 PPP Now in datatable 3, I want results whose id is not zero in datable 2 and these records should come from datatable 1 and any new entries not existing in datatable1 as well which are in datatable2. So datatable 3 becomes, Datatable 3 (result) ------------------ ID | Name ------------------ 1 XYZ 2 ZZZ 0 PPP
-
Hi I have a dataset with 2 datatables, I want to filter/compare the 2 tables and get results in way like Datatable1 ------------------ ID | Name ------------------ 1 XYZ 2 ZZZ Datatable 2 ------------------ ID | Name ------------------ 0 XYZ 0 ZZZ 0 PPP Now in datatable 3, I want results whose id is not zero in datable 2 and these records should come from datatable 1 and any new entries not existing in datatable1 as well which are in datatable2. So datatable 3 becomes, Datatable 3 (result) ------------------ ID | Name ------------------ 1 XYZ 2 ZZZ 0 PPP
asp_crazy_guy wrote:
in datatable 3, I want results whose id is not zero in datable 2
Your example shows 0 PPP in datatable 3! Assuming you dont want certain rows, two ways: 1. (better one): Do this in SQL query while fetching data filter out that are having ID 0 2. In code-behind, run two foreach loops. First one on table1 and second one on table 2. In first foreach, check the value of ID, and based on your condition if the row is fine add that to the third table. Repeat the same with second foreach loop done on table2. End result would be Table3 with data you want.
-
asp_crazy_guy wrote:
in datatable 3, I want results whose id is not zero in datable 2
Your example shows 0 PPP in datatable 3! Assuming you dont want certain rows, two ways: 1. (better one): Do this in SQL query while fetching data filter out that are having ID 0 2. In code-behind, run two foreach loops. First one on table1 and second one on table 2. In first foreach, check the value of ID, and based on your condition if the row is fine add that to the third table. Repeat the same with second foreach loop done on table2. End result would be Table3 with data you want.
Thanks for the reply. I only want to filter out records in table3 which have zero id in table2 and have a non zero id in table1. The records with zero id in table 2 and not existing in table1 are to be included in table3. Actual problem is that, 1) On a webform, there is a list of records returned from datatabase (table 1) 2) In edit form, user can edit these records from a checkbox list 3) Now for the newly selected records, I am having a zero id (all operation is done in datable) 4) For previously selected records they have a non zero id. 5) Table 1 is original records, table2 is new list after selection 6) Now on form update button I have to find which records to insert into database and which ones to drop, update etc Hope you get my point. Can you help a little bit more ?:~
-
Thanks for the reply. I only want to filter out records in table3 which have zero id in table2 and have a non zero id in table1. The records with zero id in table 2 and not existing in table1 are to be included in table3. Actual problem is that, 1) On a webform, there is a list of records returned from datatabase (table 1) 2) In edit form, user can edit these records from a checkbox list 3) Now for the newly selected records, I am having a zero id (all operation is done in datable) 4) For previously selected records they have a non zero id. 5) Table 1 is original records, table2 is new list after selection 6) Now on form update button I have to find which records to insert into database and which ones to drop, update etc Hope you get my point. Can you help a little bit more ?:~
asp_crazy_guy wrote:
- Now on form update button I have to find which records to insert into database and which ones to drop, update etc
Just use 2nd table for update. Why you need table1. Only table2 has the records that was selected and modified. No need of filter.