TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gary
NA
18
48.9k
Creating a Quiz
Jun 29 2011 8:18 AM
Hello,
I am having a problem but i'm unsure as to whether or not there is a solution to it. My intention is to create a quiz, using an Access database table to store both the questions and the answers, that is, 1 column will contain the questions, and another column will contain the answers.
I will have a C# form, which when loaded, will have a question that has been randomly chosen from the database displayed onto it.
At the moment, what I am trying to do is to get the label that I have on my form populated with the text of one of my questions in the database. Here is my code:
[Code]
private void WindowsAnalysisQuiz_Load(object sender, EventArgs e)
{
//declare connection string using windows security
string cnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Hannah\\Desktop\\WindowsAnalysisQuiz.accdb";
//declare Connection, command and other related objects
OleDbConnection conGet = new OleDbConnection(cnString);
OleDbCommand cmdGet = new OleDbCommand();
try
{
//open connection
conGet.Open();
cmdGet.CommandType = CommandType.Text;
cmdGet.Connection = conGet;
cmdGet.CommandText = "SELECT Question FROM WindowsAnalysisQuiz ORDER BY rnd()";
label1.Text = cmdGet.CommandText["Question"];
conGet.Close();
[/Code]
The line in bold is the problem I am getting. Apparently I am using invalid arguments. I have not managed to see any examples of quizzes using Access databases as a repository. It would be nice to know if I am trying to achieve something that isn't really possible!
Reply
Answers (
2
)
Code for EMI Calculation?
ConfigurationManager Class