tags:

views:

50

answers:

1

I want to make the following query dynamic.

var t = from r in dt.AsEnumerable()  
orderby r.Field< int >("id") ascending
select r;

void query(string sorttype,string sortorder)

Is it possbile to change the order by part so that those paramater will come from parameters of a function like sorttype for id in here and sortorder for ascending.

A: 

I think this ought to do it:

IEnumerable query<sorttype>(DataTable dt, string sortorder) {
    return dt.GetList().OrderBy(row => row.Field<sorttype>(sortorder));
}

Note that sorttype is a generic type parameter, not a string.

recursive
Datatable is Enumerable so it would not work that way
hrrrr
@hrrrr: you're correct, I've added a call to GetList() that should address this.http://msdn.microsoft.com/en-us/library/bb338495.aspx
recursive