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() 3 4877
fniles,
No, I don't believe you can add an index to a datatable.
Keep in mind that datasets/datatables are not the same as an in-memory sql
database and trying to treat them as such will only lead to frustration.
Having said that, if you need an index for performance while selecting, you
might look into the dataview and its find methods. It will index on whatever
you set as its sort column.
Kerry Moorman
"fniles" wrote:
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()
On Sep 18, 8:41*am, "fniles" <fni...@pfmail.comwrote:
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()
Not really. One exception is the PK which is indexed.
Thank you
How can you create PK on the dataTable ?
"Brian Gideon" <br*********@yahoo.comwrote in message
news:b1**********************************@b38g2000 prf.googlegroups.com...
On Sep 18, 8:41 am, "fniles" <fni...@pfmail.comwrote:
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()
Not really. One exception is the PK which is indexed. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Oliver Drobnik |
last post by:
Hi,
I have a datagrid bound to a datatable. Now if I sort the datagrid by
clicking on one of the column heads I can no longer use the index in the
datagrid to find the corresponding row in the...
|
by: Jason Callas |
last post by:
I have a process that manages a list of trades. Each trade is a separate row in the table. I blast the process with 10,000 new trades in order to stress test it and end up with the below listed...
|
by: Ryan |
last post by:
Is there a way to get a row's DataView index from the underlying DataTable
index.
Example
DataTable (sorted by key - 1st column) DataView (sorted by second column)
Row 0 - A, 2 ...
|
by: jensen bredal |
last post by:
Hello,
I have a Datatable "dt" with say "n" rows.
I want to return a subset of "dt" starting at index "i" (i<dt.Rows.Count)
and ending at index "j" ( dt.Rows.Count >j>i).
How can this be done...
|
by: Richard |
last post by:
Windows Forms, csharp, 20 rows in DataTable 14 shown in view after filter
applied. For any of the 14 how do I do the datarow or something else thing
to access the data in the row of the table...
|
by: JohnR |
last post by:
Sorry if this is has an obvious answer, but I can't find it...
I am using a datatable.select to obtain the rows in a datatable that meet
certain criteria. My question is this: for each of the...
|
by: =?Utf-8?B?UnlhbiBBbmRydXM=?= |
last post by:
Does the int index of the DataTable.Rows collection place a size limit on how
large a datatable can be?
If not then how do you index DataTable.Rows for sizes greater than what an
int can handle?
|
by: Ryan Liu |
last post by:
I have a program works fine in .NET 1.1 and just recompiled in .NET 2.0
without any code change. Compiles OK, but there is an exeception when
execute it.
Then I remove PK, it works all fine...
|
by: fniles |
last post by:
I am using VB.NET 2005 and Access database.
My program uses a timer that kicks in every 1 min to read from a database
and copy the dataset table to a datatable.
This database is in a class called...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |