ASP.NET & Databases Part 2
page 2 of 5
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 24739/ 52

DataSet in Action

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.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-11-26 10:13:53 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search