未从数据库中订购数据 [英] Not ordered data from database

查看:83
本文介绍了未从数据库中订购数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用此sql语句从数据库中检索数据:

Hi,

I used this sql statement to retrieve data from database:

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();



lbtnUserID.Text的值必须= 1
却给了我7

为什么yyyyyyyyyyyyyyy?

我确定数据在表中是正确排序的...

救救我

感谢



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

推荐答案

您没有在查询中使用任何"Order By"子句.因此,数据库服务器将以与数据库表中显示的顺序不同的顺序返回结果集.

使用"Order by UserId (Or, Primary key field)"很可能会解决此问题,但是,如果需要从数据库中加载特定用户,我建议您向查询中添加"Where"过滤器.例如:

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


如果您不想在进行SQL检索时进行排序,还有另一种方法.

您还可以使用DefaultView从数据表本身进行排序

对于示例

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";


这篇关于未从数据库中订购数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆