本文整理汇总了VB.NET中System.Data.DataTable.PrimaryKey属性的典型用法代码示例。如果您正苦于以下问题:VB.NET DataTable.PrimaryKey属性的具体用法?VB.NET DataTable.PrimaryKey怎么用?VB.NET DataTable.PrimaryKey使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.PrimaryKey属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: GetPrimaryKeys
Private Sub GetPrimaryKeys(table As DataTable)
' Create the array for the columns.
Dim columns As DataColumn()
columns = table.PrimaryKey
' Get the number of elements in the array.
Console.WriteLine($"Column Count: {columns.Length}")
For i = 0 To columns.GetUpperBound(0)
Console.WriteLine($"{columns(i).ColumnName} {columns(i).DataType}")
Next
End Sub
Private Sub SetPrimaryKeys()
' Create a new DataTable and set two DataColumn objects as primary keys.
Dim table As New DataTable()
Dim keys(1) As DataColumn
Dim column As DataColumn
' Create column 1.
column = New DataColumn()
column.DataType = Type.GetType("System.String")
column.ColumnName= "FirstName"
' Add the column to the DataTable.Columns collection.
table.Columns.Add(column)
' Add the column to the array.
keys(0) = column
' Create column 2 and add it to the array.
column = New DataColumn()
column.DataType = Type.GetType("System.String")
column.ColumnName = "LastName"
table.Columns.Add(column)
' Add the column to the array.
keys(1) = column
' Set the PrimaryKeys property to the array.
table.PrimaryKey = keys
End Sub