Hi! I want to select only 10 rows from a dataTable each time, just as
from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY
ID"). for example:

DataTable myTable = new DataTable("orders");
DataRow[] rows = myTable.Select("TOP 10 ID < 100");
1)How can I write the correct statement.
2)Can I ues "TOP" key word or there's other way to do it?
P.S. I mean from a dataTable.

Thank you very much. :shock:

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

RE: Select Top 10 from a DateTable??? by Rich

Rich
Fri Nov 12 16:23:01 CST 2004

Not sure if this is the best option, but you could always just grunt it out
the old-fashioned way:

Dim dr(9) as DataRow
Dim i as integer
for i=0 to 9
dr(i)=DataTable.Rows(i)
next i

...or whatever the C# equivalent woud be


"luckyShek" wrote:

> Hi! I want to select only 10 rows from a dataTable each time, just as
> from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY
> ID"). for example:
>
> DataTable myTable = new DataTable("orders");
> DataRow[] rows = myTable.Select("TOP 10 ID < 100");
> 1)How can I write the correct statement.
> 2)Can I ues "TOP" key word or there's other way to do it?
> P.S. I mean from a dataTable.
>
> Thank you very much. :shock:
>
> *-----------------------*
> Posted at:
> www.GroupSrv.com
> *-----------------------*
>

Re: Select Top 10 from a DateTable??? by JuLiE

JuLiE
Fri Nov 12 22:31:32 CST 2004

Is it feasible for you to just iterate through the DataTable grabbing
the first ten Rows from the DataTable's DataRowCollection object ?

perhaps,


DataRow[] rows = new DataRow[10];

for (int i=0 ; i < 10 ; i++)
{
rows[ i ] = myTable.Rows[ i ];
}


providing there isn't less than 10 rows present in your DataTable
object.



On 12 Nov 2004 13:57:11 -0600, vl_yes@hotmail-dot-com.no-spam.invalid
(luckyShek) wrote:

>Hi! I want to select only 10 rows from a dataTable each time, just as
>from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY
>ID"). for example:
>
>DataTable myTable = new DataTable("orders");
>DataRow[] rows = myTable.Select("TOP 10 ID < 100");
>1)How can I write the correct statement.
>2)Can I ues "TOP" key word or there's other way to do it?
>P.S. I mean from a dataTable.
>
>Thank you very much. :shock:
>
>*-----------------------*
> Posted at:
> www.GroupSrv.com
>*-----------------------*


Re: Select Top 10 from a DateTable??? by Miha

Miha
Sat Nov 13 02:09:44 CST 2004

Hi,

You should first create a DataView over the table using RowFilter = "Id<100"
and Sort = "ID" and then you should do a for loop
for (int i=0; i<9; i++)
{
DataRow rv = dv[i].Row;
}

Once you have a row, do as others suggested.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"luckyShek" <vl_yes@hotmail-dot-com.no-spam.invalid> wrote in message
news:41951597$1_3@Usenet.com...
> Hi! I want to select only 10 rows from a dataTable each time, just as
> from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY
> ID"). for example:
>
> DataTable myTable = new DataTable("orders");
> DataRow[] rows = myTable.Select("TOP 10 ID < 100");
> 1)How can I write the correct statement.
> 2)Can I ues "TOP" key word or there's other way to do it?
> P.S. I mean from a dataTable.
>
> Thank you very much. :shock:
>
> *-----------------------*
> Posted at:
> www.GroupSrv.com
> *-----------------------*