Click here to Skip to main content
16,021,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I am new in ASP.net programming.
I am trying to sort data using a mysql statement. In this program, user will enter a userID and it will show list of task for that userID. I am not sure on what command to use, but i know it is something like this:

C#
String strSQL;
           strSQL = "SELECT * FROM nametable WHERE userID=idname";


What is the proper syntax to sort mysql data through a value of a variable?

Thanks in advance.
Posted
Updated 9-Feb-13 4:35am
v2

1 solution

Hi,

Use ORDER BY:
http://www.w3schools.com/sql/sql_orderby.asp[^]
For example:
C#
String strSQL;
strSQL = "SELECT * FROM nametable WHERE userID=idname ORDER BY taskname ASC";


[EDIT after reading your comment]

Updated version of code block
C#
String strSQL;
           strSQL = "SELECT * FROM nametable WHERE userID='" + idname + "'"; // in this case, idname is a variable in your code file
 
Share this answer
 
v3
Comments
jmpapa 9-Feb-13 10:54am    
Thanks for the fast response.

But this program should only show tasks created by a single user.
Let me clarify it, this is actually an online to-do list. Once the user log-in, all the tasks created by him will be retrieved.

So, it is something like.. select * from tasktable where userid = idname (*idname used in log-in)

But, I don't know what the correct command to use.
Thomas Daniels 9-Feb-13 10:56am    
I updated my answer.
jmpapa 9-Feb-13 11:16am    
Thanks.
But, I'm recieving this error
~You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1'''
Thomas Daniels 9-Feb-13 11:20am    
You wrote the apostrophes? If <small>idname</small> is an integer, don't write the apostrophes. If <small>idname</small> isn't an integer, write the apostrophes.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900