本文整理匯總了VB.NET中System.Data.ConstraintCollection類的典型用法代碼示例。如果您正苦於以下問題:VB.NET ConstraintCollection類的具體用法?VB.NET ConstraintCollection怎麽用?VB.NET ConstraintCollection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ConstraintCollection類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MakeTableWithUniqueConstraint
Private Sub MakeTableWithUniqueConstraint()
Dim table As New DataTable("table")
Dim column As New DataColumn("UniqueColumn")
column.Unique = True
table.Columns.Add(column)
' Print count, name, and type.
Console.WriteLine("Constraints.Count " _
+ table.Constraints.Count.ToString())
Console.WriteLine(table.Constraints(0).ConstraintName)
Console.WriteLine( _
table.Constraints(0).GetType().ToString())
' 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.ToString())
Console.WriteLine(table.Constraints(1).ConstraintName)
Console.WriteLine( _
table.Constraints(1).GetType().ToString())
End Sub
Private Sub MakeTableWithForeignConstraint()
' Create a DataSet.
Dim dataSet As New DataSet("dataSet")
' Make two tables.
Dim customersTable As New DataTable("Customers")
Dim ordersTable As New DataTable("Orders")
' Create four columns, two for each table.
Dim name As New DataColumn("Name")
Dim id As New DataColumn("ID")
Dim orderId As New DataColumn("OrderID")
Dim orderDate As New DataColumn("OrderDate")
' Add columns to tables.
customersTable.Columns.Add(name)
customersTable.Columns.Add(id)
ordersTable.Columns.Add(orderId)
ordersTable.Columns.Add(orderDate)
' Add tables to the DataSet.
dataSet.Tables.Add(customersTable)
dataSet.Tables.Add(ordersTable)
' Create a DataRelation for two of the columns.
Dim myRelation As New DataRelation _
("CustomersOrders", id, orderId, True)
dataSet.Relations.Add(myRelation)
' Print TableName, Constraints.Count,
' ConstraintName and Type.
Dim t As DataTable
For Each t In dataSet.Tables
Console.WriteLine(t.TableName)
Console.WriteLine("Constraints.Count " _
+ t.Constraints.Count.ToString())
Console.WriteLine("ParentRelations.Count " _
+ t.ParentRelations.Count.ToString())
Console.WriteLine("ChildRelations.Count " _
+ t.ChildRelations.Count.ToString())
Dim cstrnt As Constraint
For Each cstrnt In t.Constraints
Console.WriteLine(cstrnt.ConstraintName)
Console.WriteLine(cstrnt.GetType())
Next cstrnt
Next t
End Sub