当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET ConstraintCollection类代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:75,代码来源:ConstraintCollection


注:本文中的System.Data.ConstraintCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。