Index on DataTable ?

F

fniles

Can I create an index on a DataTable ?
On the following DataTable, I would like to create index on "Price", can I
do that ?
Thank you.

Dim DT As New DataTable

DT.Columns.Add("Price", GetType(System.Int32))
DT.Columns.Add("ID", GetType(System.Int32))
DT.Columns.Add("Vol", GetType(System.Int32))

Dim r As DataRow = DT.NewRow
r.Item(0) = 99
r.Item(1) = 1234
r.Item(2) = 350
r.Item(3) = 1
DT.Rows.Add(r)

r = DT.NewRow
r.Item(0) = 98
r.Item(1) = 1233
r.Item(2) = 300
r.Item(3) = 1
DT.Rows.Add(r)

r = DT.NewRow
r.Item(0) = 97
r.Item(1) = 1230
r.Item(2) = 375
r.Item(3) = 1
DT.Rows.Add(r)

r = DT.NewRow
r.Item(0) = 96
r.Item(1) = 1231
r.Item(2) = 250
r.Item(3) = 1
DT.Rows.Add(r)
DT.AcceptChanges()
 
J

Jay B. Harlow [MVP - Outlook]

Creating a DataView on a DataTable effectively creates an index for those
columns on that DataTable.

Dim dv As New DataView(DT, Nothing, "Price",
DataViewRowState.CurrentRows)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top