Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting unrelated rows from a DataTable
Message
 
To
20/05/2005 08:49:46
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01016157
Message ID:
01016168
Views:
8
This message has been marked as a message which has helped to the initial question of the thread.
Andrew,

I'd probably do it using a stored procedure that either takes a few parameters (if the number of PKs is going to be very small and limited) or a single string parameter (that would consist of a comma delimited list of PKs). I guess you could also pass in the WHERE clause like this:
DataTable.Select["pk IN (@pk1, @pk2, @pk3, @pk4)"];
HTH,
Chad

>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
_________________________________
There are 2 types of people in the world:
    Those who need closure
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform