think_big
think_big

Reputation:

Is there any non-dummy way to get only 100 rows from a DataTable in C#?

I want to get, let's say 100 records from an already populated DataTable with let's say 150.000 records. I don't wanna do this with a loop or importing rows. There should be a more efficent and easy way to do this, and i'm not finding it. I tried using

myDataTable.Select("ROWNUM < 100"); // because i'm working with oracle

but RowNum is not a column of the table.

Any hint and help is highly appreciated! Thnx in advance.

Upvotes: 0

Views: 276

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500775

If you're using .NET 3.5, you can use the AsEnumerable extension method, and then Take:

IEnumerable<DataRow> rows = myDataTable.AsEnumerable().Take(100);

Are you sure you can't do this at population time though? You don't really want to be pulling 150,000 items from the server if you can help it...

Upvotes: 2

Related Questions