Skip to content

Commit e017f48

Browse files
Youssef1313Ron Petrusha
authored andcommitted
Update source.vb (#1569)
1 parent f79c38d commit e017f48

File tree

1 file changed

+37
-38
lines changed
  • snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData DataTable.PrimaryKey Example/VB

1 file changed

+37
-38
lines changed

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData DataTable.PrimaryKey Example/VB/source.vb

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
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
55

66

7-
Public Class Form1: Inherits Form
7+
Public Class Form1 : Inherits Form
88

99
Protected DataSet1 As DataSet
1010
Protected DataGrid1 As DataGrid
1111

1212
' <Snippet1>
1313
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
2423
End Sub
2524

2625
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
4140

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)
4746

48-
' Add the column to the array.
49-
keys(1) = column
47+
' Add the column to the array.
48+
keys(1) = column
5049

51-
' Set the PrimaryKeys property to the array.
52-
table.PrimaryKey = keys
50+
' Set the PrimaryKeys property to the array.
51+
table.PrimaryKey = keys
5352
End Sub
5453
' </Snippet1>
5554

0 commit comments

Comments
 (0)