Hi,
I am developing a quiz contest in before starting the quiz user is to select the types of question(combobox) & number of question and when the button is clicked we go to next quiz form in the question is displayed in textbox and option is displayed on 4 different buttons when we press one any button if it is right then backcolor of button is green else red.And when we press next button then next question is displayed and soon(question limit is 10).
Thanks.

What's the question?

You don't seem to have a question in there, just a statement of what you want to do. Since we don't do your work for you, you'll have to do some and then if you get stuck, ask :)

I will tell you that depending on choices you make about the database design, your life will be easy or hard :)

I just need a clue how to do that

If am correct you want to generate random question from the database.

Possible solution is to retrive all question specified by your criteria in the database, then you will enumarate it and pick one by one "You can set a variable here that will change value from true or false everytime it loop" and save all picked question on to the collection.

That all, you already have the set of questions.

Yeah you are right...
Can it possible retrive question to textbox an option to buttons(i.e 4) and if button is clicked it matches the text from database if answer is right display green else red color..

-make two tables, first one(subjects or themes whatever this is called, for example geography, astronomy mathematics, medicine, physics... depending on your questions). Second one(questions, all sorts of questionS no matter the subject).

-make a realtionship 1:n
-well this is it concerning the database ( you could add some aditional stuff but I think this is enough.

-assuming that you have data inside now... proceeding with c#,sql...

-fill your combobox with the a sql statement,, example: SELECT Theme.Subject FROM THEME // once you read the statement you can easily use combobox.Items.Add(dr[0].ToString());

  • your combobox is filled with the themes/subjects(geography,maths...)

  • now when you click on a item let's say geography ,,, save that item as a string in a variable (store that in a variable when th selected_index_changed event fires.

-produce another sql statement for instance: SELECT QUESTION.name FROM QUESTION WHERE QUESTION.SubjectID=Theme.ID AND THEME.Subject=@selecteditem_of_combobox
-add your selecteditem, for MSSQL this would go like this:

 cmd.Parameters.Add(newSqlParameter("selecteditem_of_combobox",variable_value));

- Now inside your sql statement you could have used a random function but I' m not sure wich sql software are you using so I will leave that up to you.
- If you don't want to use the rand() function in sql you can always access the random c# class.
-once you read the question from your db I would store them in a list and then do something similar to this:

Random rnd= new Random();
int random_numb = rnd.Next(list.Count);
textbox1.Text=(string)list[random_numb];

then you would get a random question which is connected to your selected theme.
-then do whatever else you want...
-avoid the concatenation in your sql statements it is not good, search on google why...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.