當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET UniqueConstraint構造函數代碼示例

本文整理匯總了VB.NET中System.Data.UniqueConstraint.UniqueConstraint構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET UniqueConstraint構造函數的具體用法?VB.NET UniqueConstraint怎麽用?VB.NET UniqueConstraint使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在System.Data.UniqueConstraint的用法示例。


在下文中一共展示了UniqueConstraint構造函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: CreateUniqueConstraint

Private Sub CreateUniqueConstraint(ByVal dataSetSuppliers As DataSet)
    Dim uniqueConstraint As UniqueConstraint

    ' Get the DataColumn of a table in a DataSet.
    Dim dataColumn As DataColumn
    dataColumn = dataSetSuppliers.Tables("Suppliers").Columns("SupplierID")

    ' Create the constraint.
    uniqueConstraint = New UniqueConstraint("supplierIdConstraint", dataColumn)

    ' Add the constraint to the ConstraintCollection of the DataTable.
    dataSetSuppliers.Tables("Suppliers").Constraints.Add(uniqueConstraint)
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Data,代碼行數:13,代碼來源:UniqueConstraint

示例2: MakeTableWithUniqueConstraint

Private Sub MakeTableWithUniqueConstraint()
    ' Create a DataTable with 2 DataColumns.
    Dim dataTable As New DataTable("dataTable")
    Dim idColumn As New DataColumn( _
        "ID", System.Type.GetType("System.Int32"))
    Dim nameColumn As New DataColumn( _
        "Name", System.Type.GetType("System.String"))
    dataTable.Columns.Add(idColumn)
    dataTable.Columns.Add(nameColumn)

    ' Run procedure to create a constraint.
    AddUniqueConstraint(dataTable)

    ' Add one row to the table.
    Dim dataRow As DataRow
    dataRow = dataTable.NewRow()
    dataRow("ID") = 1
    dataRow("Name") = "John"
    dataTable.Rows.Add(dataRow)

    ' Display the constraint name.
    Console.WriteLine(dataTable.Constraints(0).ConstraintName)

    ' Try to add an identical row,
    ' which throws an exception.
    Try
        dataRow = dataTable.NewRow()
        dataRow("ID") = 1
        dataRow("Name") = "John"
        dataTable.Rows.Add(dataRow)
    Catch ex As Exception
        Console.WriteLine("Exception Type: {0}", ex.GetType())
        Console.WriteLine("Exception Message: {0}", ex.Message)
    End Try
End Sub

Private Sub AddUniqueConstraint(ByVal dataTable As DataTable)
    ' Create the DataColumn array.
    Dim dataColumns(1) As DataColumn
    dataColumns(0) = dataTable.Columns("ID")
    dataColumns(1) = dataTable.Columns("Name")

    ' Create the constraint on both columns.
    Dim uniqueConstraint As UniqueConstraint = _
        New UniqueConstraint("idNameConstraint", dataColumns)
    dataTable.Constraints.Add(uniqueConstraint)
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Data,代碼行數:47,代碼來源:UniqueConstraint


注:本文中的System.Data.UniqueConstraint.UniqueConstraint構造函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。