Click here to Skip to main content
15,916,019 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Q no 1. Two trains running in opposite directions cross a man standing on the platform in 27 seconds and 17 seconds respectively and they cross each other in 23 seconds. The ratio of their speeds is:

a. 1 : 3
b. 3 : 2
c. 3 : 4
d. None of these


My page is something like this, i want to rearrange the options on every refresh. i m displaying all the questions and answers from the database on Grid View.
Posted
Comments
Sergey Alexandrovich Kryukov 30-Jan-12 0:38am    
Useless shuffle, useless tests. How much longer shall we tolerate this humiliation of education? Until the whole population on the planet is "educated" into zombie?
--SA

In Database(SQL Server), Shuffle the Rows using NEWID() or RAND in SELECT clause

EDIT
Generate random sets in SQL Server[^]
 
Share this answer
 
v2
Comments
Abhinav S 30-Jan-12 0:50am    
Yes that is a good solution. 5.
Rockstar_ 30-Jan-12 1:03am    
can u provide the querry plz....
thatraja 30-Jan-12 1:20am    
Check my updated answer
manognya kota 30-Jan-12 4:58am    
good one . +5
You can use the Rand class in C# to generate random numbers.
Here[^] is a simple example in ASP.Net.
 
Share this answer
 
Comments
thatraja 30-Jan-12 1:47am    
Right, 5!
Abhinav S 30-Jan-12 1:49am    
Thanks thatraja.
manognya kota 30-Jan-12 4:58am    
Good one.+5
Abhinav S 30-Jan-12 5:25am    
Thanks.
SQL
alter
Procedure GetRandomOptions

as

Begin

Create
Table #Options(ID int identity(1,1),Fields nvarchar(10))
Insert
into #Options

Select
COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME='Questions' And COLUMN_NAME like 'O%' Order By NEWID()

--Select * from #Options

Declare
@RandomCols nvarchar(100)

Set
@RandomCols=''

Select
@RandomCols=@RandomCols+Fields+' ,' from #Options

--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O1,')

+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))

--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O2,')

+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))

--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O3,')

+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))

--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O4,')

+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))

--Set @RandomCols=SUBSTRING(@RandomCols,0,len(@RandomCols))

--Select @RandomCols

Declare
@strQry nvarchar(MAX)

Set
@strQry=''

Set
@strQry='Select QID,Ques,'+@RandomCols+'Ans from Questions '
exec
(@strQry)

End

SQL

 
Share this answer
 

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