Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Filter 2 datatables in dataset

Filter 2 datatables in dataset

Scheduled Pinned Locked Moved ASP.NET
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeego
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • Z zeego

      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

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      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.

      Z 1 Reply Last reply
      0
      • S Sandeep Mewara

        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.

        Z Offline
        Z Offline
        zeego
        wrote on last edited by
        #3

        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 ?:~

        S 1 Reply Last reply
        0
        • Z zeego

          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 ?:~

          S Offline
          S Offline
          Sandeep Mewara
          wrote on last edited by
          #4

          asp_crazy_guy wrote:

          1. 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups