本文整理匯總了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