一:Clone返回新的 DataTable
Clone返回新的 DataTable,与当前的 DataTable 具有相同的架构;Copy:返回新的 DataTable,它具有与该 DataTable 相同的结构(表架构和约束)和数据
DataRow[] _dr = DT.Select("CLSSBH='"+ Filter_Str +"'");
DataTable dt = DT.Clone() ;
DataRow dr ;
for( int j = 0 ;j < _dr.Length ;j ++ )
{
dr = dt.NewRow() ;
dr = _dr[j] ;
dt.ImportRow( dr ) ;
}
我一般使用DataTable.Rows.Add(row.ItemArray);
DataTable.ImportRow(row)
二:DataRowCollection.Find (Object) 获取由主键值指定的行。
DataRowCollection.Find (Object[]) 获取包含指定的主键值的行。
private void FindInMultiPKey(DataTable myTable){
DataRow foundRow;
// Create an array for the key values to find.
object[]findTheseVals = new object[3];
// Set the values of the keys to find.
findTheseVals[0] = "John";
findTheseVals[1] = "Smith";
findTheseVals[2] = "5 Main St.";
foundRow = myTable.Rows.Find(findTheseVals);
// Display column 1 of the found row.
if(foundRow != null)
Console.WriteLine(foundRow[1]);
}
三
DataTable.Select方法
{
DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string = "Date > '1/1/00'";
// Sort descending by column named CompanyName.
string sortOrder = "CompanyName DESC";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
foundRows = table.Select(, sortOrder);
// Print column 0 of each returned row.
for(int j = 0; j < foundRows.Length; j ++)
{
Console.WriteLine(foundRows[j][0]);
}
}