get new dataset from common records of 2 sets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Garima12
    New Member
    • Mar 2007
    • 58

    get new dataset from common records of 2 sets

    there r 2 datasets and I want to get 3rd dataset containing the records which are common in 1st and 2nd datasets. common field in dataset 1 n 2 is id. what is the best method to do it?
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    I would loop through dataset1, and for each record loop through dataset2, adding the row only when it is in common.

    Not very efficient (n^2) but the only way I know how.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      If both Tables are in a single DataSet object, you might be able to do something with a DataAdapter? I'm not sure as I've never tried.

      Comment

      • Garima12
        New Member
        • Mar 2007
        • 58

        #4
        Originally posted by Plater
        If both Tables are in a single DataSet object, you might be able to do something with a DataAdapter? I'm not sure as I've never tried.
        plater,
        there r 2 datasets, not 2 tables.

        Comment

        • Garima12
          New Member
          • Mar 2007
          • 58

          #5
          Originally posted by insertAlias
          I would loop through dataset1, and for each record loop through dataset2, adding the row only when it is in common.

          Not very efficient (n^2) but the only way I know how.
          i thought the same way, loop through both datasets, but when i try to add common records in new dataset, it throws error, can you tell me by example?

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Originally posted by Garima12
            i thought the same way, loop through both datasets, but when i try to add common records in new dataset, it throws error, can you tell me by example?
            You need to use .ImportRow(data Row)

            Example
            Code:
            //c#
            DataTable2.ImportRow(DataTable1.Rows[0]);
            That would copy row 0 from DataTable1 to DataTable2. That should be enough to get you started.

            Comment

            Working...