
September 24th, 2012, 06:36 AM
|
|
Contributing User
|
|
Join Date: Mar 2011
Posts: 125
Time spent in forums: 1 Day 1 h 59 m 59 sec
Warnings Level: 5
Reputation Power: 0
|
|
|
Query for get data from table:
Hi
Please find the answer.
Query for get data from table:
Select q.Q-No, q.Question, q.Answers1, q.Answers2, q.Answers3, q.Answers4, a.correctanswer from Questions q inner join Answers a on q.Q-no=a.Q-no
There can be two approaches further using dataset or datatable and class object or class type list (Incase we need to fetch multiple questions)
Result set of the query can be saved in class object which contains all the above fields as properties by using datareader.
Let’s assume we are using class Quize which contains below properties
Q-No
Question
Answers1
Answers2
Answers3
Answers4
correctanswer
At front end :
Lets assume obj is Quize class type object containing the values fetch from the database
Qnotxt.text= obj.Q-No.ToString();
Qtext.text= obj. Question.ToString();
Rdb1.text = obj. Answers1.ToString();
Rdb1.text = obj. Answers2.ToString();
Rdb1.text = obj. Answers3.ToString();
Rdb1.text = obj. Answers4.ToString();
*For multiple questions we could have used list of Quize type List<Quize>
Thanks
Diya
|