Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting unrelated rows from a DataTable
Message
From
20/05/2005 08:49:46
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Getting unrelated rows from a DataTable
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01016157
Message ID:
01016157
Views:
46
Hi,

How can I get a subset of rows from a DataTable when all I have is a collection of primary keys? The rows that I want from the DataTable have no common data/keys so I unfortunately can't just use DataTable.Select("someColumn = @someValue"). From an SQL perspective the question be : I have a fistfull of primary key values and I want to retrieve the rows that have those primary key values)

The two ways that I have thought of and partly rejected are :

1. use DataTable.Select(string filter) and pass in an OR filter string that is built up of the primary keys that I want rows for. For example :

DataTable.Select["pk = @pk1 OR pk = @pk2 OR pk = @pk3 OR ...").

This seems like a brute force solution that is open to all kinds of problems and I would like to avoid it if I could.

2. Iterate through the collection of PKs and build up a collection of the rows that I want. For example :

RowCollection rowsThatIWant = new RowCollection();
foreach(object PK in PKCollection)
{
DataRow foundRow = DataTable.Rows.Find(PK);
rowsThatIWant.Add(foundRow);
}

I am afraid that this solution could take a long time if the collection of PKs is big (execution time is an important feature for our application)

Any better solutions would be greatly appreciated,

Andrew
Next
Reply
Map
View

Click here to load this message in the networking platform