闲话少说,上代码
public static DataTable Join(DataTable left, DataTable right,
DataColumn[] leftCols, DataColumn[] rightCols,
bool includeLeftJoin, bool includeRightJoin)
{
DataTable result = new DataTable("JoinResult");
using (DataSet ds = new DataSet())
{
ds.Tables.AddRange(new DataTable[] { left.Copy(), right.Copy() });
DataColumn[] leftRelationCols = new DataColumn[leftCols.Length];
for (int i = 0; i < leftCols.Length; i++)
leftRelationCols[i] = ds.Tables[0].Columns[leftCols[i].ColumnName];
DataColumn[] rightRelationCols = new DataColumn[rightCols.Length];
for (int i = 0; i < rightCols.Length; i++)
rightRelationCols[i] = ds.Tables[1].Columns[rightCols[i].ColumnName];
//create result columns
for (int i =