order by sql query in databound gridview doesnt work?

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?
 
C

Clodoaldo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top