Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#

Hello, I have a task to make a quiz in C# WPF using the SQLite database.

I made a connection with the database Quiz with 7 Columns:

0. ID
1. Question
2. AnswerA
3. AnswerB
4. AnswerC
5. AnswerD
6. CorrectAnswer

Also, I have form from where I can add or delete questions and answers.

Now, the problem is:

When I click Start Quiz it's should open a new form that has a label with a random question from the database and 4 RadioButton with text from columns AnswerA, b, c, and D.

Any idea how could I make this?

Thank You.

What I have tried:

C#

I tried to Google solution but I didn't even find how to store info form database to radiobutton.text

Posted
Updated 3-Jun-20 2:02am
Comments
ZurdoDev 3-Jun-20 7:57am    
"click Start Quiz it's should open a new form that has a label with a random question from the database and 4 RadioButton with text from columns AnswerA, b, c, and D."

There are a lot of tasks in that request. So, where are you stuck?

1. You need a new form with a label on it and some radiobuttons.
2. You need to know how to open the form.
3. You need to know how to generate a random number between 1 and the number of questions you have.
4. You need to know how to retrieve a record from the database and populate the values in a control.
5. etc, etc. etc.

Break it down into the parts and then ask something specific.
F-ES Sitecore 3-Jun-20 7:58am    
Your question is basically "how do I write this program". We don't mind giving specific answers to specific questions but this is too broad and vague. Break the problem into smaller problems and solve each one in turn. So find out how to select a random item from a SQLite database. Then find out how you use radio buttons, then find out how to store data in SQLite and so on.

You need to learn how to break you problem into bite-size pieces

1) the first query you should do is a count of the number of rows (questions) in your table
2) you then generate a random number between 0 and # rows - 1
3) (this assumes the ID is sequential) from 2 you do a select where ID = the random number

....

I guess, since re-reading your question you say you can delete rows, you could replace 1,2 with
1) get a list of all valid ID's in the table
2) pick an ID randomly
3) get the matching row by ID

Once you get this far, you then have a row in your sql result that you can use to update the GUI

There are other ways of doing this of course
 
Share this answer
 
v2

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