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
Databinding to Group of Radio Buttons Problem
Jun 30 2011 9:23 AM
Hello,
I am frustrated, I can't seem to get anything to work. Here is my problem. I have a group of radio buttons on my C# form. I have 4 of these radio buttons. I have a database, structured like this:
Question | Answer 1| Answer 2 | Answer 3 | Answer 4 | Correct Answer
#value# #value #value #value #value #value
My aim is to bind the values of the columns Answer 1, Answer 2, Answer 3 and Answer 4 to the respective radio button in the list, so that:
radio button 1 will have the value of the column Answer 1
radio button 2 will have the value of the column Answer 2
radio button 3 will have the value of the column Answer 3
radio button 4 will have the value of the column Answer 4
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\\Quiz.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.CommansText = "SELECT
//cmdGet.CommandText = "SELECT Question, [Correct Answer], Answer2, Answer3, Answer4 FROM Quiz()";
cmdGet.CommandText = "SELECT Question FROM Quiz";
OleDbDataReader reader = cmdGet.ExecuteReader();
reader.Read();
label1.Text = reader["Question"].ToString();
//radioButton.Text = cnString["Quiz"].Rows[0]["Correct Answer"].ToString();
groupBoxAnswers.Text = reader["Answer1"].ToString();
//radioButton.Text = reader["Correct Answer"].ToString();
//radioButton1.Text = reader["Answer2"].ToString();
//radioButton2.Text = reader["Answer3"].ToString();
//radioButton3.Text = reader["Answer4"].ToString();
conGet.Close();
}
[/code]
Instead of getting the possible answers from the database written to each radio button, I am getting a textbox appear saying 'Answer1'. I've no idea how to overcome this problem. There is a lot of ASP code for this problem but nothing of use for C#
Reply
Answers (
5
)
Report Viewer Issuse
Regex problem