Click here to Skip to main content
12,253,679 members (62,707 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
{
       Sql = "select * from BirthDayWish where Active = 'A'";
       Dr = SCon.ReadSql(Sql);
       GridView1.DataSource = Dr;
       GridView1.DataBind();
       GridView1.Visible = true;
   }


in the above sql query.
Sql = "select * from BirthDayWish where Active = 'A'";
i want to use OrderBy Name.

how to use.

i am using the below query,this is correct.

sql="select * from BirthDayWish OrderBy Name where Active='A'";

the above query is correct.


pleae help me.and send the query;
Posted 27-Dec-12 0:01am
Edited 27-Dec-12 2:29am
ridoy57.8K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Order By[^] Clause comes after Where clause.
So your query should be
select * from BirthDayWish where Active='A' Order By [Name] 
  Permalink  
v2
Comments
Aarti Meswania 27-Dec-12 7:01am
   
My 5+! :)
__TR__ 27-Dec-12 7:18am
   
Thank you Aarti.
Aarti Meswania 27-Dec-12 7:21am
   
welcome! :)
__TR__ 27-Dec-12 7:18am
   
Thank you Mitesh.
Madhuri Patil 27-Dec-12 8:18am
   
My 5
__TR__ 27-Dec-12 11:08am
   
Thank you Madhuri.
ridoy 27-Dec-12 8:29am
   
+5
__TR__ 27-Dec-12 11:08am
   
Thank you ridoy.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi it would be much better if specify all columns that you want to fetch:

sql="select Id,Name,Active from BirthDayWish WHERE Active='A' Order By Name ASC";
  Permalink  
Comments
Oleksandr Kulchytskyi 27-Dec-12 7:37am
   
I knew it ;)
But anyway thanks, i think it will be useful for questioner!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

{
 Sql = "select * from BirthDayWish where Active = 'A'";
 Dr = SCon.ReadSql(Sql);
 Dr.DefaultView.Sort = "Name ASC";
 GridView1.DataSource = Dr;
 GridView1.DataBind();
 GridView1.Visible = true;
 }
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try This
In Ascending Order By Name:
select * 
from BirthDayWish 
where Active = 'A'
Order By Name
In Descending Order By Name:
select *
from BirthDayWish
where Active = 'A'
Order By Name Desc
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100