order by sql query in databound gridview doesnt work?

  • Thread starter Thread starter Sunfire
  • Start date Start date
S

Sunfire

I have a GridView hooked up to an objectDataSource. I need the gridView to
sort the rows by a particular column. I went into the dataSet that my object
accesses and changed the query from:
select NewsId, Date, Title, Text from NewsArticles;
to: select NewsId, Date, Title, Text from NewsArticles order by Date DESC;

My sort works, but there is 1 interesting issue with it. I had all news
items sorted in order by date ASC before and it worked. When I reversed the
order, the results were in order (sort of), 2 of them were out of order. My
sql table looks like this:
create table NewsArticles
NewsId int not null,
Date char(10) not null,
Title varchar(50) not null,
Text text not null)...
any reason why this might be happening?
 
I have a GridView hooked up to an objectDataSource. I need the gridView to
sort the rows by a particular column. I went into the dataSet that my object
accesses and changed the query from:
select NewsId, Date, Title, Text from NewsArticles;
to: select NewsId, Date, Title, Text from NewsArticles order by Date DESC;

My sort works, but there is 1 interesting issue with it. I had all news
items sorted in order by date ASC before and it worked. When I reversed the
order, the results were in order (sort of), 2 of them were out of order. My
sql table looks like this:
create table NewsArticles
NewsId int not null,
Date char(10) not null,
Title varchar(50) not null,
Text text not null)...
any reason why this might be happening?

Change the date data type to DateTime or use the date in this format:
YYYYMMDD or YYYY/MM/DD.

Clodoaldo
 
Back
Top