更新时间:2023-11-30 22:41:22
//<summary>
/// Routine to filter first table and replace exiting table with filtered records.
// </summary>
// <param name="sourceSet">Dataset instance to be manipulated</param>\n
private void _FilterAndInsert(DataSet sourceSet)
{
///Apply your filter clauses in Select() function parameter
DataRow[] rows = sourceSet.Tables[0].Select("filter clauses here...");
///Get the structure of source table
DataTable tempTable = sourceSet.Tables[0].Clone();
///Add the filtered rows in temp table
foreach (DataRow row in rows)
{
tempTable.Rows.Add(row.ItemArray);
}
tempTable.AcceptChanges();
///Create new dataset
DataSet resultSet = new DataSet();
///Add temp table at first index or modify this code sequence as you require
resultSet.Tables.Add(tempTable);
for (int index = 1; index < sourceSet.Tables.Count; index++)
{
///Set the copy of source table in local instance
DataTable tableToAdd = sourceSet.Tables[index].Copy();
///Remove from source to avoid any exceptions
sourceSet.Tables.RemoveAt(index);
///Add the copy to result set
resultSet.Tables.Add(tableToAdd);
}
///Set the copy to source table from result set
sourceSet = resultSet.Copy();
}
ADO.NET使您可以创建DataTable对象并将其添加到现有DataSet中.您可以使用PrimaryKey和Unique属性为DataTable设置约束信息.
有关更多信息,请检查此
http://msdn.microsoft.com/en-us/library/aeskbwf7%28v = vs.80%29.aspx [ ^ ]
ADO.NET enables you to create DataTable objects and add them to an existing DataSet. You can set constraint information for a DataTable by using the PrimaryKey and Unique properties.
For more information check this
http://msdn.microsoft.com/en-us/library/aeskbwf7%28v=vs.80%29.aspx[^]