将数据库中的ID随机化并存储到数组中 [英] randomise id from database and store into array
本文介绍了将数据库中的ID随机化并存储到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据我的数据库随机分配ID.
例如,我需要调出topicid = 1
的所有内容
主题1有26个问题
我需要随机分配10个(不可重复)
存储在数组会话中.
谢谢.
how to randomise id based on my database.
eg i need to call out everything for topicid = 1
and there are 26 questions for topic 1
i need to randomised and call out 10 (non repeatable)
store in array session.
thanks.
推荐答案
针对您的数据库执行此查询:
Hi,
Execute this query against your db:
SELECT TOP 10 *
FROM
[YourTableName]
WHERE
topicid = 1
ORDER BY NEWID()
并使用经典的ADO.NET(SqlConnection,SqlCommand,SqlDataReader)将数据放入数组...
and use classic ADO.NET (SqlConnection, SqlCommand, SqlDataReader) to get your data into array...
请参阅此
http://haacked.com/archive/2004/06/21/658.aspx [ ^ ]
http://stackoverflow.com/questions/3293643/random-questions-from-sql-server [^ ]
Refer this
http://haacked.com/archive/2004/06/21/658.aspx[^]
http://stackoverflow.com/questions/3293643/random-questions-from-sql-server[^]
这篇关于将数据库中的ID随机化并存储到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文