c# 對兩個datatable的結構相同進行合併:
datatable db=null;
datatable dt = ds.tables[0];
兩個datatable進行合併
db = dt.copy();
datarow foundrows = dt.select();
for (int i = 0; i < foundrows.length;i++)
//兩個結構一樣的dt合併
datatable datatable1 = new datatable();
datatable datatable2 = new datatable();
datatable newdatatable = datatable1.clone();
object obj = new object[newdatatable.columns.count];
for (int i = 0; i < datatable1.rows.count; i++)
for (int i = 0; i < datatable2.rows.count; i++)
//兩個結構不同的dt合併
///
/// 將兩個列不同的datatable合併成乙個新的datatable
///
/// 表1
/// 表2
/// 合併後新的表名
///
private datatable unitedatatable( datatable dt1 ,datatable dt2 ,string dtname)
object obj = new object[dt3.columns.count];
for (int i = 0; i < dt1.rows.count; i++)
if( dt1.rows.count >= dt2.rows.count ) }
} else
for( int i = 0 ;i < dt2.rows.count ;i++ ) }
} dt3.tablename = dtname ; //設定dt的名字
return dt3 ;
} //多個 結構相同的datatable合併
public datatable getallentrysdatatable() }
return newdatatable;
}
c 對兩個Datatable的結構相同進行合併
datatable db null datatable dt ds.tables 0 兩個datatable進行合併 db dt.copy datarow foundrows dt.select for inti 0 i foundrows.length i 兩個結構一樣的dt合併 datatabl...
合併兩個DataTable
方法1 sqlconnection myconnection new sqlconnection server localhost uid sa pwd database wjoa string sql1 select from resoursemanage t sqldataadapter ada...
連線兩個DataTable表
在c 中把兩個datatable連線起來,相當於sql的inner join方法 public static datatable join datatable first,datatable second,datacolumn fjc,datacolumn sjc datacolumn parent...