Order result sql

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have to do a select in one table, and i have to order the result by one column, what's the better object to use dataset, datatable???

Thanks

Silvia
 
a dataset is just a collection of datatables - so they don't do the same
thing. You can have a datatable that's in a dataset, or not - but the 2
objects have completely different jobs.

If you can't sort the result when you are doing the select from the
database, then you can define a dataview on a datatable, and set the sort in
the dataview. Then use your dataview as your datasource, while will provide
a sorted view of the underlying data.

Silvia said:
Hi,

I have to do a select in one table, and i have to order the result by one
column, what's the better object to use dataset, datatable???
 
Hi Silvia,

Marina is right...all you have to do is set the DataView's DataSource property to the DataTable (whether or not it is a member of a DataSet). Then set the DataView's Sort property to your column name. (Append DESC to the end for descending order...ASC is the default.) A simple example, where LastName and FirstName are DataTable columns:

DataView1.Sort = "LastName, FirstName DESC"

However, if at all possible, include an ORDER BY clause in your T-SQL SELECT statement before your data even reaches your application. This will prevent binding context position problems when inserting and deleting records from the underlying DataTable.

Take care,

Eric
 
Hi Silvia,

In addition to the others

Have a look as well for dataview rowfilter instead of select

Cor
 
Back
Top