本文整理汇总了C#中System.Data.ConstraintCollection类的典型用法代码示例。如果您正苦于以下问题:C# ConstraintCollection类的具体用法?C# ConstraintCollection怎么用?C# ConstraintCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstraintCollection类属于System.Data命名空间,在下文中一共展示了ConstraintCollection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MakeTableWithUniqueConstraint
private void MakeTableWithUniqueConstraint()
{
DataTable table = new DataTable("table");
DataColumn column = new DataColumn("UniqueColumn");
column.Unique=true;
table.Columns.Add(column);
// Print count, name, and type.
Console.WriteLine("Constraints.Count "
+ table.Constraints.Count);
Console.WriteLine(table.Constraints[0].ConstraintName);
Console.WriteLine(table.Constraints[0].GetType() );
// Add a second unique column.
column = new DataColumn("UniqueColumn2");
column.Unique=true;
table.Columns.Add(column);
// Print info again.
Console.WriteLine("Constraints.Count "
+ table.Constraints.Count);
Console.WriteLine(table.Constraints[1].ConstraintName);
Console.WriteLine(table.Constraints[1].GetType() );
}
private void MakeTableWithForeignConstraint()
{
// Create a DataSet.
DataSet dataSet = new DataSet("dataSet");
// Make two tables.
DataTable customersTable= new DataTable("Customers");
DataTable ordersTable = new DataTable("Orders");
// Create four columns, two for each table.
DataColumn name = new DataColumn("Name");
DataColumn id = new DataColumn("ID");
DataColumn orderId = new DataColumn("OrderID");
DataColumn cDate = new DataColumn("OrderDate");
// Add columns to tables.
customersTable.Columns.Add(name);
customersTable.Columns.Add(id);
ordersTable.Columns.Add(orderId);
ordersTable.Columns.Add(cDate);
// Add tables to the DataSet.
dataSet.Tables.Add(customersTable);
dataSet.Tables.Add(ordersTable);
// Create a DataRelation for two of the columns.
DataRelation myRelation = new
DataRelation("CustomersOrders",id,orderId,true);
dataSet.Relations.Add(myRelation);
// Print TableName, Constraints.Count,
// ConstraintName and Type.
foreach(DataTable t in dataSet.Tables)
{
Console.WriteLine(t.TableName);
Console.WriteLine("Constraints.Count "
+ t.Constraints.Count);
Console.WriteLine("ParentRelations.Count "
+ t.ParentRelations.Count);
Console.WriteLine("ChildRelations.Count "
+ t.ChildRelations.Count);
foreach(Constraint cstrnt in t.Constraints)
{
Console.WriteLine(cstrnt.ConstraintName);
Console.WriteLine(cstrnt.GetType());
}
}
}
开发者ID:.NET开发者,项目名称:System.Data,代码行数:73,代码来源:ConstraintCollection
注:本文中的System.Data.ConstraintCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论