I have a datatable where I would like to move all the rows that have a certain firstname and lastname to the top of the table.
public DataTable SortByFirstNameAndLastNameMatch(DataTable table, string firstName, string lastName)
{
DataTable ret = new DataTable();
foreach (DataRow dataRow in table.Rows)
{
if (dataRow["NomArtiste"].ToString().ToLower() == lastName.ToLower() && dataRow["PrenomArtiste"].ToString().ToLower() == firstName.ToLower())
{
ret.ImportRow(dataRow);
}
}
ret.Merge(table);
return RemoveDuplicateRows(ret, "AlbumID");
}
Is there a way I can do this using a linq expression or a comparer without making a new datatable?
.AsEnumerable()(msdn.microsoft.com/en-us/library/…) on theDataTablethen you can apply all the LINQ sorting/filtering/transforming/etc. that you want on it.