在vb.net中随机排序数据表 [英] Sorting a datatable randomly in vb.net
问题描述
DataBase新手。我有一个sql server数据库,其中一个数据表连接到我的应用程序。我希望每次应用程序启动时都会随机对这个数据表的行进行排序。我该怎么做?
我正在尝试进行测验。我的数据表有四个colomns(第一个包含一个问题,另外三个包含答案)。所以我希望每次游戏开始时问题都以随机顺序出现。我尝试使用bindingsource.sort但它没有工作
我的第一个想法是你添加一个列。对于每一行,您都会生成一个随机数,并用它填充该列。然后按该列排序。
Google Results for Generating a随机数 [ ^ ]
尝试使用以下SQL读取数据
SELECT TOP100 百分比 * FROM [yourtable] ORDER BY newid()
您可以更改百分之百 - 我只是假设你想要整张桌子。
你也可以放弃百分比
来得到例如100个问题。
通过 Ralph Shillington [ ^ ]
New to DataBase. I have a sql server database with one datatable connected to my application. I want the rows of this datatable to be sorted randomly each time the application starts. How do I do that?
[Edit - further detail from OP]
I''m trying to make a quiz. My datatable has four colomns (the first holds a question and the other three hold the answers). So I want the questions to appear in random order each time the game starts. I tried to use bindingsource.sort but it didn''t work
My first thought is that you add a column. For each row you generate a random number and populate that column with it. Then sort by that column.
Google Results for Generating a Random Number[^]
Try reading the data with the following SQL
SELECT TOP 100 percent * FROM [yourtable] ORDER BY newid()
You can change the 100 percent - I just assumed you''d want the entire table.
You could also drop thepercent
to get e.g. 100 questions.
With acknowledgements to Ralph Shillington[^]
这篇关于在vb.net中随机排序数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!