Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort in DataSet vs. Sort in SQL Query

Status
Not open for further replies.

lunchbox88

Programmer
Feb 17, 2004
208
US
Since sorting records in a SQL makes the query run slower, I was wondering if it was possible and/or beneficial to do the sorting after the Dataset has been populated.
 
It's very possible and usually preferred.

Microsoft made a class called a DataView especially for sorting and filtering data in a DataTable.

Check it out:

The primary advantages are:

1. you take load off the database server (allowing it to simply fetch, not manipulate data)

-and-

2. extrodinary flexibility. With a DataView, you are not limited to a default sort or filter of the SQL statement. You can change sort criteria, sort direction, and filter criteria all on the fly. This allows you to, for example, let the user change which column of a datagrid to use for sorting after they click on a column header.
 
Downside would be if you're doing any result-set paging. By doing the sort on the client-side, when they go to the next page they see data starting over at "A", when they might have expected it to start with "R" or something.

Sort on DB Server with "Order By":
[tt]Page 1
[tab]A
[tab]B
[tab]C
Page 2
[tab]D
[tab]E
[tab]F

Sort on client side with grid:
Page 1
[tab]A
[tab]C
[tab]E
Page 2
[tab]B
[tab]D
[tab]F[/tt]

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top