Display data in sorting order using gridview with c# code [Resolved]

Posted by Mandlaa under ASP.NET on 1/24/2014 | Points: 10 | Views : 946 | Status : [Member] | Replies : 4
I am writing this query for displaying data in sorting order but it's not working

SqlDataAdapter da = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and(h.ClientId = " + Session["ClientId"] + ")order by t.Tagusage;", con); 


Correct my code




Responses

Posted by: kgovindarao523-21772 on: 1/24/2014 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Try like this.
SqlDataAdapter da = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t 

INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId = " + Session["ClientId"] + " order by t.Tagusage ASC;",con);



Thank you,
Govind

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down

Resolved
Incorrect syntax near 'DES'

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: muralikrishnasurap-12704 on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
Hi Try this also
SqlDataAdapter da = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t 
INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId = " + Session["ClientId"] + " order by t.Tagusage DES;",con);


Best Regards
Murali Krishna.S

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Snaveen on: 2/13/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

first off all i give you one suggestion don't write complex queries on your application. Better to use Stored Procedure to do this. If you wrote complex queries in application then it's very tough to understand the code.

Use below sample for sorting purpose.

EX:

select * from tablename

order by colname


Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response