Vijay
Vijay

Reputation: 383

Length function in Datatable.Select sort expression

Am trying to sort the selected rows from a DataTable as follows.

dt.Select("ImageUrl LIKE '%" + FilePath + "%'", "LEN(ImageUrl) DESC, ImageUrl DESC");

But it throws an error saying column LEN(ImageUrl) is invalid. Can anyone suggest how to achieve this?

Thanks.

Upvotes: 0

Views: 696

Answers (1)

Gaurav Jain
Gaurav Jain

Reputation: 444

You can use linq for this

     IEnumerable<DataRow> drarray;
    drarray = dt.Select().Where(ex =>   
    ex.ItemArray[0].ToString().Contains(FilePath)).OrderByDescending(ed =>   
    ed.ItemArray[0].ToString().Length).ThenByDescending(ed => ed.ItemArray[0].ToString().Length);

     foreach(DataRow dr1 in drarray){
        //your code
    }

      where itemarray[0] is index of your column field in datataable. 

Upvotes: 1

Related Questions