Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I used this sql statement to retrieve data from database:

SQL
select UserID from  Users


but when i receive data by like this code, the records in dataset is not ordered like in the database table:

lbtnUserID.Text = usersEditDataSet.Tables[0].Rows[0]["UserID"].ToString();


the value of lbtnUserID.Text must be = 1
but it gives me 7

whyyyyyyyyyyyyyyyyy?

I am sure that the data is ordered right in table......

Help me plz

thanks
Posted
Updated 26-Dec-10 18:31pm
v2

You are not using any "Order By" clause in your query. So, the database server is returning the result set in an order which is not having the same order shown in the database table.

Most probably, using an "Order by UserId (Or, Primary key field)" would solve this issue, but, I would recommend you to add a "Where" filter to your query if you need to load a specific user from the database. For example:

SELECT UserId from Users WHERE UserId = 1
 
Share this answer
 
Comments
MrLonely_2 27-Dec-10 1:00am    
Thanks man........ but i want to get all users from database.......but i did not use order by as i suspect that it will be ordered with primay key field by default.....
but now i used order by and it is succeeded ...... thanks man.......many kisses
There's another alternate way if you don't want to sort at a time of SQL retrieval.

You can also sort from datatable itself using DefaultView

For Ex.

usersEditDataSet.Tables[0].DefaultView.Sort = "UserID ASC";
 
Share this answer
 
Comments
MrLonely_2 27-Dec-10 7:58am    
very good idea.... thank u very much .........

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