本文整理汇总了C#中System.Data.DataTableCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# DataTableCollection.Remove方法的具体用法?C# DataTableCollection.Remove怎么用?C# DataTableCollection.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataTableCollection
的用法示例。
在下文中一共展示了DataTableCollection.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveTables
private void RemoveTables()
{
// Set the name of the table to test for and remove.
string name = "Suppliers";
// Presuming a DataGrid is displaying more than one table, get its DataSet.
DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
DataTableCollection tablesCol = thisDataSet.Tables;
if (tablesCol.Contains(name) && tablesCol.CanRemove(tablesCol[name]))
tablesCol.Remove(name);
}
示例2: DataTableCollectionCanRemove
public static void DataTableCollectionCanRemove()
{
// create a DataSet with two tables
DataSet dataSet = new DataSet();
// create Customer table
DataTable customersTable = new DataTable("Customers");
customersTable.Columns.Add("customerId",
typeof(int) ).AutoIncrement = true;
customersTable.Columns.Add("name",
typeof(string));
customersTable.PrimaryKey = new DataColumn[]
{ customersTable.Columns["customerId"] };
// create Orders table
DataTable ordersTable = new DataTable("Orders");
ordersTable.Columns.Add("orderId",
typeof(int) ).AutoIncrement = true;
ordersTable.Columns.Add("customerId",
typeof(int) );
ordersTable.Columns.Add("amount",
typeof(double));
ordersTable.PrimaryKey = new DataColumn[]
{ ordersTable.Columns["orderId"] };
dataSet.Tables.AddRange(new DataTable[]
{customersTable, ordersTable });
// remove all tables
// check if table can be removed and then
// remove it, cannot use a foreach when
// removing items from a collection
while(dataSet.Tables.Count > 0)
{
DataTable table = dataSet.Tables[0];
if(dataSet.Tables.CanRemove(table))
{
dataSet.Tables.Remove(table);
}
}
Console.WriteLine("dataSet has {0} tables",
dataSet.Tables.Count);
}