In
action
We'll
create a simple dataset that we can use throughout this part.
Dim ds1 As New DataSet()
Dim dtable As new DataTable("people")
With dtable.Columns
.Add("FName", System.Type.GetType("System.String"))
.Add("LName", System.Type.GetType("System.String"))
.Add("UID", System.Type.GetType("System.Int32"))
End With
dtable.Columns("UID").AutoIncrement = True
ds1.Tables.Add(dtable) |
dim pkey() as DataColumn = {ds1.Tables("people").Columns("UID")}
ds1.Tables("people").PrimaryKey = pkey |
This
is a bit complicated so I separated it into two boxes.
Box
1: Ok, we declare a new dataset and
a datatable which we call - "people" as you can see in the parameters.
The dTable.Columns collection has a function - add, that lets you add columns
with the syntax - (column name, type). After adding three columns, we define
the "UID" column as AutoIncrement (these properties are part of the DataColumn
object). You can also set things like the Seed, caption, etc.
We then add the DataTable to the DataSet.
Box
2: This creates a array of
DataColumn objects (in this case, only the UID column) and then tell the
dataset that this array has a datacolumn that we want to be a primary key
This
is a bit complicated so you don't really need to worry that much about box 2.
We'll be going over the stuff to help you understand this next.