tags:

views:

59

answers:

3
+1  Q: 

DataSet Operations

I'm working with DataSets, specifically with a an array of DataRows:

My question is, how am I able to perform Unions/Intersects of DataRow[]'s WITHOUT using LINQ?

+3  A: 

Personally, I do it by using Relations between the tables.

David Stratton
It really depends on whether the FK Relationships are on the actual database he's reading from. It's a real pain to define them manually.
C. Ross
+3  A: 

Use Relations

RandomNoob
Yeah. What I said... I'll vote you up for that.
David Stratton
+3  A: 

Just write code for it:

//Assumes setA and setB are unique internally
   public DataRow[] GetUnionRows(DataRow[] setA, DataRow[] setB){
      List<DataRow> resultList = new List<DataRow>(setA);
      foreach (DataRow row in setB){
          if (!Contains(setA, row)){
             resultList.add(row);
          }
      }
      return resultList.toArray();
   }

   private bool YourEquals(DataRow a, DataRow b){
      //Whatever
   }

   private bool Contains(DataRow[] setA, DataRow b){
      foreach(DataRow a in setA){
         if (YourEquals(a,b)){
            return true;
         }  
      }
      return false;
   }
C. Ross
And that's worh an upvote too.
David Stratton