Should I sort my resultsets before loading them into a DataSet? RRS feed

  • Question

  • Hello


    I have a DataSet with 2 related DataTables, in a master-detail disposition. The data comes from a stored procedure that returns 2 resultsets. In order to achieve the best loading performance: Should I sort the resultsets in the stored procedure? Or placing the "ORDER BY" is useless in this scenario?


    Thanks a lot.

    Wednesday, July 30, 2008 3:59 PM


  • It depends on what you need to achieve. When data loaded into DataTable, you will have limited functionality to do actual sorting inside of DataTable and it could be faster to do it using ORDER BY in your SQL statement. But you could create sorted DataView on a client, which could be enought for you and in this case you do not need to sort data on server side. If you need to set relationships between those two DataTable on client side, then it probably does not matter if data is sorted or not, since ADO.NET will use its own internal indexes to search for the related records inside of DataTables.


    Thursday, July 31, 2008 10:00 AM