Adding a non unique index to a datatable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a large datatable in a typed dataset, on which I run the select method
with three different filters. I'm looking for a way to have three NON UNIQUE
indexes so that the select method is much more eficient. The dataset
designer only lets me add unique indexes (or am I missing something?). The
rows I find need to be edited, so a dataview does not seem to be appropriate
(again, am I missing something?).

Is there no easy way to add a NON UNIQUE index to a datable, either in the
designer or at runtime?

thanks!
 
Hi,

According to your description, I understand you want to get a way to set
NON Unique index to make select method much efficient. Please don't
hesitate to correct me know if I have misunderstood anything here.

In DataTable , the select method will search for the Primary Key. Each
Primary Key should be unique. So that it is not possible to set NON UNIQUE
index to DataTable level.

However, in DataView level, the find/findrows method will search against
Sort property. It is not necessary of UNIQUE constraint on this property.
For this reason, I suggest you may look up for it.

Set DataTableView.sort to the column and select the rows by find method.
DataView dv = new DataView(dt);
dv.Sort = "c1";
dv.FindRows();

http://msdn2.microsoft.com/en-us/library/wtkx6bz9.aspx
[DataView.FindRows Method (Object)]

Hope this helps. If you have anything unclear, please feel free to let me
know. I'm glad to assist you.
Sincerely
Wen Yuan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi mudGil,
The answer of Wen Yuan is the solution to filter within the DataTable /
DataView, but may be you shoud think about filter directly in the database
(if you could...)

Regards,
 
WenYuan, Thanks for your response. You understood my question exactly. I
have already hit upon the DataView.find method. Two questions -

1) Is the row that is returned updatetable? This is a must, as I am
building the dataset in memory in stages and there are an order of 50,000
searches of this type that then need to update several columns in the
returned row.
2) if the row is updatetable, there still is the question of when is the
index created. If an index will be built 50,000 times, the performance will
likely not be very good...

Waht is the simple answer - is there realy no way to add a non PK index to a
dataset, either programaticaly or in the designer?

thanks again
--
They d on''''t make bugs like bunny anymore


WenYuan Wang said:
Hi,

According to your description, I understand you want to get a way to set
NON Unique index to make select method much efficient. Please don't
hesitate to correct me know if I have misunderstood anything here.

In DataTable , the select method will search for the Primary Key. Each
Primary Key should be unique. So that it is not possible to set NON UNIQUE
index to DataTable level.

However, in DataView level, the find/findrows method will search against
Sort property. It is not necessary of UNIQUE constraint on this property.
For this reason, I suggest you may look up for it.

Set DataTableView.sort to the column and select the rows by find method.
DataView dv = new DataView(dt);
dv.Sort = "c1";
dv.FindRows();

http://msdn2.microsoft.com/en-us/library/wtkx6bz9.aspx
[DataView.FindRows Method (Object)]

Hope this helps. If you have anything unclear, please feel free to let me
know. I'm glad to assist you.
Sincerely
Wen Yuan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi mudGil,
Thanks for you reply.
1) Is the row that is returned updatetable?
Yes, the row returned from DataView is updateable. If you change the row,
the change will also reflect in your DataTable. Additionally, you can get
the original row by DataRowView.Row Property.
2) if the row is updatetable, there still is the question of when is the
index created.
The index will be created when the dataview is created, and also if you
change the sort, rowfilter and rowstate property of the dataview.

What is the simple answer - is there realy no way to add a non PK index to
a dataset, either >programaticaly or in the designer?
In short, it is not possible to add a non PK index to a dataset, either
programmatically or designer. The index in datatable should always be
Primary Key.

Hope this helps. Please let me know if you still have anything unclear.
Sincerely,
Wen Yuan
Microsoft Online Community Support
 
Hi mudGil,

I haven't heard from you two days. Have you resolve the issue now?
If there is anything we can help with, please update here and I will follow
up.I'm glad to work with you.

Have a great weekend,
Sincerely,
Wen Yuan
Microsoft Online Community Support
 
Back
Top