Working with Datatable.

  • Thread starter Thread starter jensen bredal
  • Start date Start date
J

jensen bredal

Hello,
I have a Datatable "dt" with say "n" rows.
I want to return a subset of "dt" starting at index "i" (i<dt.Rows.Count)
and ending at index "j" ( dt.Rows.Count >j>i).
How can this be done without unnecessary coding?


Many thanks in advance.

JB
 
Hi,

Use the DataView.RowFilter or DataTable.Select(...)
More info in .NET docs.

Marcin
 
Use the DataView.RowFilter or DataTable.Select(...)
More info in .NET docs.
Right but i will have to write some fairly complex sql script. I thought
there was
some more straight forward way out.
Thank you anyway.


JB
 
Hi again,
Right but i will have to write some fairly complex sql script. I thought
there was
some more straight forward way out.
Thank you anyway.

I understand that you want to return some DataRow(s) that
have indices between i and j (e.g. 11 - 20). I'm right?

If i'm right:
DataRow[] selectedRows=new DataRow[(j-i)+1];
for(int index=0; index<selectedRows.Length; index++) {
selectedRows[index]=dataTable.Rows[i+index];
}

HTH
Marcin
 
If i'm right:
DataRow[] selectedRows=new DataRow[(j-i)+1];
for(int index=0; index<selectedRows.Length; index++) {
selectedRows[index]=dataTable.Rows[i+index];
}

HTH
Marcin

very impressive!

Thanks.

JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top