|
1 |
| -imports System.Xml |
2 |
| -imports System.Data |
3 |
| -imports System.Data.Common |
4 |
| -imports System.Windows.Forms |
| 1 | +Imports System.Xml |
| 2 | +Imports System.Data |
| 3 | +Imports System.Data.Common |
| 4 | +Imports System.Windows.Forms |
5 | 5 |
|
6 | 6 |
|
7 |
| -Public Class Form1: Inherits Form |
| 7 | +Public Class Form1 : Inherits Form |
8 | 8 |
|
9 | 9 | Protected DataSet1 As DataSet
|
10 | 10 | Protected DataGrid1 As DataGrid
|
11 | 11 |
|
12 | 12 | ' <Snippet1>
|
13 | 13 | Private Sub GetPrimaryKeys(table As DataTable)
|
14 |
| - ' Create the array for the columns. |
15 |
| - Dim columns() As DataColumn |
16 |
| - columns = table.PrimaryKey |
17 |
| - |
18 |
| - ' Get the number of elements in the array. |
19 |
| - Console.WriteLine("Column Count: " & columns.Length.ToString()) |
20 |
| - Dim i As Integer |
21 |
| - For i = 0 To columns.GetUpperBound(0) |
22 |
| - Console.WriteLine(columns(i).ColumnName & columns(i).DataType.ToString()) |
23 |
| - Next i |
| 14 | + ' Create the array for the columns. |
| 15 | + Dim columns As DataColumn() |
| 16 | + columns = table.PrimaryKey |
| 17 | + |
| 18 | + ' Get the number of elements in the array. |
| 19 | + Console.WriteLine($"Column Count: {columns.Length}") |
| 20 | + For i = 0 To columns.GetUpperBound(0) |
| 21 | + Console.WriteLine(columns(i).ColumnName & columns(i).DataType.ToString()) |
| 22 | + Next |
24 | 23 | End Sub
|
25 | 24 |
|
26 | 25 | Private Sub SetPrimaryKeys()
|
27 |
| - ' Create a new DataTable and set two DataColumn objects as primary keys. |
28 |
| - Dim table As New DataTable() |
29 |
| - Dim keys(2) As DataColumn |
30 |
| - Dim column As DataColumn |
31 |
| - |
32 |
| - ' Create column 1. |
33 |
| - column = New DataColumn() |
34 |
| - column.DataType = System.Type.GetType("System.String") |
35 |
| - column.ColumnName= "FirstName" |
36 |
| - |
37 |
| - ' Add the column to the DataTable.Columns collection. |
38 |
| - table.Columns.Add(column) |
39 |
| - ' Add the column to the array. |
40 |
| - keys(0) = column |
| 26 | + ' Create a new DataTable and set two DataColumn objects as primary keys. |
| 27 | + Dim table As New DataTable() |
| 28 | + Dim keys(1) As DataColumn |
| 29 | + Dim column As DataColumn |
| 30 | + |
| 31 | + ' Create column 1. |
| 32 | + column = New DataColumn() |
| 33 | + column.DataType = System.Type.GetType("System.String") |
| 34 | + column.ColumnName= "FirstName" |
| 35 | + |
| 36 | + ' Add the column to the DataTable.Columns collection. |
| 37 | + table.Columns.Add(column) |
| 38 | + ' Add the column to the array. |
| 39 | + keys(0) = column |
41 | 40 |
|
42 |
| - ' Create column 2 and add it to the array. |
43 |
| - column = New DataColumn() |
44 |
| - column.DataType = System.Type.GetType("System.String") |
45 |
| - column.ColumnName = "LastName" |
46 |
| - table.Columns.Add(column) |
| 41 | + ' Create column 2 and add it to the array. |
| 42 | + column = New DataColumn() |
| 43 | + column.DataType = System.Type.GetType("System.String") |
| 44 | + column.ColumnName = "LastName" |
| 45 | + table.Columns.Add(column) |
47 | 46 |
|
48 |
| - ' Add the column to the array. |
49 |
| - keys(1) = column |
| 47 | + ' Add the column to the array. |
| 48 | + keys(1) = column |
50 | 49 |
|
51 |
| - ' Set the PrimaryKeys property to the array. |
52 |
| - table.PrimaryKey = keys |
| 50 | + ' Set the PrimaryKeys property to the array. |
| 51 | + table.PrimaryKey = keys |
53 | 52 | End Sub
|
54 | 53 | ' </Snippet1>
|
55 | 54 |
|
|
0 commit comments