Newbee question.

J

jensen bredal

Hello,
I'm wondering about how to accomplish an apparent simple thing.
I read from a cached dataset in an asp.net application cache as shown
below:

// Set a filter on the view of the Calls table.
dsBoth.Tables["Calls"].DefaultView.RowFilter = "ContactID=" +
drpContacts.SelectedItem.Value.ToString();
// Bind to the data grid.
grdCalls.DataBind();


Note that the "RowFilter" property of the DefaultView only seem to accept
what would come after the "where" clause in an sql statement. right?

What is i want add a select top(50) * ...., How do i proceed ?

Many thanks in advance

JB
 
W

W.G. Ryan eMVP

Add a DataColumn to you datatable and set the AutoIncrment value to true.
This will create a sequence for you. Make sure the data is sorted
beforehand in the order that you want. THen you can just use Rowfilter =
"ComputedColumn < 50"
 
J

jensen bredal

W.G. Ryan eMVP said:
Add a DataColumn to you datatable and set the AutoIncrment value to true.
This will create a sequence for you. Make sure the data is sorted
beforehand in the order that you want. THen you can just use Rowfilter =
"ComputedColumn < 50"
This is obiously the most qualified answer i have been looking for for days
now.

Thank you so much

JB.
 
G

Guest

There is no direct method to do it. If your source have any running number
then u can say {dsBoth.Tables["Calls"].DefaultView.RowFilter = "ID>0 and
ID<50"}

if you dont have any such fields in your database, then you could use
DataTable events to generate one such column in your local datatable.

eg:
Query: select 0 as ID,ContactID from Calls
/* ID column is used for creating local running number*/

Use data adapter fill method to fill the table.
Attach RowChanged event handler to datatable before using it.
inside the event handler do the following.
protected static void OnRowChanged(object sender, DataRowChangeEventArgs
args)
{
/* 0 indicates that the event is raised for the first time. Next time this
event is raised because of this id change. we should ignore this.*/

if(int.Parse(args.Row["ID"].ToString()) == 0)
{
args.Row["ID"] = args.Row.Table.Rows.Count + 1;
}
}

Then for the defaultView row filter say RowFilter = "ID >=1 and ID<=50" to
get top 50 records.

Hope this helps!!
Ural
 

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

Top