欢迎来到天天文库
浏览记录
ID:38217926
大小:21.00 KB
页数:4页
时间:2019-06-07
《两个 DataTable 合并 inner join 内连接》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、两个DataTable合并innerjoin内连接publicstaticDataTableJoin(DataTableFirst,DataTableSecond,DataColumn[]FJC,DataColumn[]SJC){//创建一个新的DataTableDataTabletable=newDataTable("Join");//UseaDataSettoleverageDataRelationusing(DataSetds=newDataSet()){//把DataTableCopy到DataSet中ds.Table
2、s.AddRange(newDataTable[]{First.Copy(),Second.Copy()});DataColumn[]parentcolumns=newDataColumn[FJC.Length];for(inti=0;i3、i4、i].ColumnName,First.Columns[i].DataType);}for(inti=0;i5、ble.Columns.Add(Second.Columns[i].ColumnName+"_Second",Second.Columns[i].DataType);}table.BeginLoadData();foreach(DataRowfirstrowinds.Tables[0].Rows){//得到行的数据DataRow[]childrows=firstrow.GetChildRows(r);if(childrows!=null&&childrows.Length>0){object[]parentarray=firs6、trow.ItemArray;foreach(DataRowsecondrowinchildrows){object[]secondarray=secondrow.ItemArray;object[]joinarray=newobject[parentarray.Length+secondarray.Length];Array.Copy(parentarray,0,joinarray,0,parentarray.Length);Array.Copy(secondarray,0,joinarray,parentarray.Len7、gth,secondarray.Length);table.LoadDataRow(joinarray,true);}}}table.EndLoadData();}returntable;}publicstaticDataTableJoin(DataTableFirst,DataTableSecond,DataColumnFJC,DataColumnSJC){returnJoin(First,Second,newDataColumn[]{FJC},newDataColumn[]{SJC});}//////da8、tatableinnerjoin合并///////////////
3、i4、i].ColumnName,First.Columns[i].DataType);}for(inti=0;i5、ble.Columns.Add(Second.Columns[i].ColumnName+"_Second",Second.Columns[i].DataType);}table.BeginLoadData();foreach(DataRowfirstrowinds.Tables[0].Rows){//得到行的数据DataRow[]childrows=firstrow.GetChildRows(r);if(childrows!=null&&childrows.Length>0){object[]parentarray=firs6、trow.ItemArray;foreach(DataRowsecondrowinchildrows){object[]secondarray=secondrow.ItemArray;object[]joinarray=newobject[parentarray.Length+secondarray.Length];Array.Copy(parentarray,0,joinarray,0,parentarray.Length);Array.Copy(secondarray,0,joinarray,parentarray.Len7、gth,secondarray.Length);table.LoadDataRow(joinarray,true);}}}table.EndLoadData();}returntable;}publicstaticDataTableJoin(DataTableFirst,DataTableSecond,DataColumnFJC,DataColumnSJC){returnJoin(First,Second,newDataColumn[]{FJC},newDataColumn[]{SJC});}//////da8、tatableinnerjoin合并///////////////
4、i].ColumnName,First.Columns[i].DataType);}for(inti=0;i5、ble.Columns.Add(Second.Columns[i].ColumnName+"_Second",Second.Columns[i].DataType);}table.BeginLoadData();foreach(DataRowfirstrowinds.Tables[0].Rows){//得到行的数据DataRow[]childrows=firstrow.GetChildRows(r);if(childrows!=null&&childrows.Length>0){object[]parentarray=firs6、trow.ItemArray;foreach(DataRowsecondrowinchildrows){object[]secondarray=secondrow.ItemArray;object[]joinarray=newobject[parentarray.Length+secondarray.Length];Array.Copy(parentarray,0,joinarray,0,parentarray.Length);Array.Copy(secondarray,0,joinarray,parentarray.Len7、gth,secondarray.Length);table.LoadDataRow(joinarray,true);}}}table.EndLoadData();}returntable;}publicstaticDataTableJoin(DataTableFirst,DataTableSecond,DataColumnFJC,DataColumnSJC){returnJoin(First,Second,newDataColumn[]{FJC},newDataColumn[]{SJC});}//////da8、tatableinnerjoin合并///////////////
5、ble.Columns.Add(Second.Columns[i].ColumnName+"_Second",Second.Columns[i].DataType);}table.BeginLoadData();foreach(DataRowfirstrowinds.Tables[0].Rows){//得到行的数据DataRow[]childrows=firstrow.GetChildRows(r);if(childrows!=null&&childrows.Length>0){object[]parentarray=firs
6、trow.ItemArray;foreach(DataRowsecondrowinchildrows){object[]secondarray=secondrow.ItemArray;object[]joinarray=newobject[parentarray.Length+secondarray.Length];Array.Copy(parentarray,0,joinarray,0,parentarray.Length);Array.Copy(secondarray,0,joinarray,parentarray.Len
7、gth,secondarray.Length);table.LoadDataRow(joinarray,true);}}}table.EndLoadData();}returntable;}publicstaticDataTableJoin(DataTableFirst,DataTableSecond,DataColumnFJC,DataColumnSJC){returnJoin(First,Second,newDataColumn[]{FJC},newDataColumn[]{SJC});}//////da
8、tatableinnerjoin合并///////////////
此文档下载收益归作者所有