Question

I'm waaaay above my level of understanding here but have a simple request to change the sort order of data in a .NET datagrid. The system seems to use SubSonic to do the database queries, so there's a level of abstraction which I just don't understand and can't seem to guess at ;).

There is a line under the gridview control in the .aspx file like this:

<asp:ObjectDataSource ID="odsCsvReport" runat="server" SelectMethod="FetchAll" TypeName="WFlower.CsvReportController">
</asp:ObjectDataSource> 

I've searched the project for 'CsvReportController' and there is a file in App_Code called 'CsvReportController.cs' in which there's a class like this:

    [DataObjectMethod(DataObjectMethodType.Select, true)]
    public CsvReportCollection FetchAll()
    {
        CsvReportCollection coll = new CsvReportCollection();
        Query qry = new Query(CsvReport.Schema);
        //qry.OrderDesc("CsvReportID");
        coll.LoadAndCloseReader(qry.ExecuteReader());
        return coll;
    }

Now, I've just no idea how to get this data to be sorted by the 'CsvReportID' field in descending order (currently it's ascending).

Can anyone shed any light on this. Like I say, I'm in too deep here but it should be such a minor thing to do I'm determined to get to the bottom of it!

Thanks folks!

EDIT: Okay, so as per @Mike Walsh's comment below, I tried this instead:

var qry = new Select().From(CsvReport.Schema); 
qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); 
return qry.ExecuteAsCollection<CsvReportCollection>();

Now however, this throws a completely different error elsewhere:

Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'.
The statement has been terminated.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'.
The statement has been terminated.

Source Error: 

Line 187:      //Do database management.
Line 188:      int removedUsers = SPs.Hg_DeleteInactiveUsers(14).Execute();
Line 189:      int removedOrders = SPs.Hg_DeleteInactiveOrders(14).Execute();
Line 190:    }
Was it helpful?

Solution

Can't remember the exact differences in 2.1-2.2-2.3 but will this compile for you?

    var qry = new Select().From(CsvReport.Schema); 
    qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID}); 
    return qry.ExecuteAsCollection<CsvReportCollection>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top