2011-01-06 2 views
1

저는 C#, 을 사용하여 ASP.NET에서 작업하고 있습니다. 두 데이터 세트의 데이터를 두 데이터 세트에있는 "ID"와 비교 한 다음 모든 일치 항목을 추가해야합니다 행을 새 데이터 집합에 추가합니다.두 데이터 세트를 비교하고 새 데이터 세트에 값 배치

+3

이 문제를 직접 해결하려고 시도한 적이 있습니까? 어떤 어려움을 겪고 있습니까? 아니면 아무런 연구도하지 않은 채 완전한 해결책을 제공하기를 원하십니까? –

답변

1

각 DataSet의 테이블간에 DataRelation을 설정 한 다음 GetChildRows 메서드를 사용하여 새 DataSet 또는 다른 데이터 구조에 추가 할 수있는 항목을 찾습니다. 몇 가지 예는 Introduction to DataRelation Objects을 참조하십시오.

0

이 두 datatables

using System.Data; 

public static class DataTableExtensions 
{ 
    public static IEnumerable<DataRow> Intersect(this DataTable table, DataTable other) 
    { 
     return table.AsEnumerable().Intersect(other.AsEnumerable()); 
    } 

    public static IEnumerable<DataRow> Intersect(this DataTable table, DataTable other, IEqualityComparer<DataRow> comparer) 
    { 
     return table.AsEnumerable().Intersect(other.AsEnumerable(), comparer); 
    } 
} 

의 교차하여 수행 할 수는 shameless port of an elegant solution :

당신이 SET1하고 싶어 비교 설정 2 개의 데이터 세트가 있다고 가정합니다. 이 작업을 수행하십시오

var newtable = set1.Tables[0].Intersect(set2.Tables[0]).CopyToDataTable(); 

게시자가 원하는 것이 아닌 경우 자세한 내용을 게시하십시오.

+0

이것이 어떻게 도움이됩니까? intersect가 행 관계를 어떻게 정의합니까? – TalentTuner

+0

"나는 두 DataSets의 데이터를 스키마가 동일한 경우 DataSets"thats intersection "에있는"ID "와 비교해야합니다. – naveen

관련 문제