从SQL数据库中获取随机问题 [英] Fetch Random Question from SQL Database

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

问题描述

先生,

我的数据库就像

Sir,

My database is like

--------------------------------
NO            int
Question      vachar(50)
op1           vachar(20)
op2           vachar(20)
op3           vachar(20)
op4           vachar(20)
Ans           vachar(20)
Subjectcode   varchar(20)
----------------------------------


数据库中包含大量有关各种SubjectCode的问题.

我想从基于subjectCode的数据库中获取一些问题,并从此获取的问题数中,我想在网页上显示随机问题(每页一个问题)

所以我希望你能帮助我...

非常感谢....


Database has large number of questions of various SubjectCode.

I want to fetch some number of question from database based on subjectCode and from this numberof fetched question I want to display random question on to the web-page (one question per page)

So I hope you will help me...

Thanks a lot....

推荐答案

您可以获取表中行的select count(*) from tablename,并使用.net Random类. />
You can get the select count(*) from tablename of the row in the table, and use the .net Random class.
Random r = new Random();
int i = r.Next(countFromTheTable)+1; // zero based add 1


请在使用DetailsView的随机问题(帮助)中找到正确答案 [在线测验 [如何从SQL表 [
Please go through correct answer in Random Questions using DetailsView (Help)[^].

Best Codeproject Articles

1. Online Quiz[^]
2. How to make a random selection from an SQL table[^]


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

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