开发者

Ensure a datatable is ordered by a value

I have a complex algorithm which I am not going to explain here. The code pasted below is doing some processing for each row, but I need to ensure that the table is ordered by a field different than the Primary Key. I need to do this in this code, not in SQL, or in stored procedures; it needs to be done in .net just before the foreach.

NO LINQ IS ALLOWED, ITS .NET 2.0 THX

Your help is appreciated.

List<int> distinctREFMDossierIds = GetREFMDossierIdsFromBookings();
foreach (int refmDossierId in distinctREFMDossierIds)开发者_Python百科
{
    bool errorsFoundInDetails = false;
    bool errorsFoundInHeaders = false;
    wingsBookingInterfaceIdswithErrors.Clear();
    dicRows.Clear();
    sbWingsBookingInterfaceIds= new StringBuilder();    
    YBooking booking = new YBooking();

    foreach (UC090_WingsIntegrationDataSet.WingsBookingInterfaceRow row in _uc090_WingsIntegrationDataSet.WingsBookingInterface.Rows)
    {
      //code
    }


You can use LINQ:

foreach(var row in _uc090_WingsIntegrationDataSet.WingsBookingInterface
                     .OrderBy(r => r. Something))


You can sort a DataTable like this:

DataTable dt = new DataTable();
dt.DefaultView.Sort = <Sort expression>;
dt = dt.DefaultView.ToTable();


WingsBookingInterface.Rows.OrderBy(item => item.columnName);


You can sort a collection ( for example a List<> ) with the OrderBy extension method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜