Stella Bloom

Stella Bloom

  • NA
  • 17
  • 1.3k

i want to match the radiobutton options with C# sql

Jul 26 2017 2:55 PM
i want to match the radiobutton options with correct ans in data base but what i did is
its just giving right for wrong, and viceversa
private void answer()
{
string Answer;
int score = 0;
SqlConnection con = new SqlConnection();
string cmd2= "SELECT Answer FROM Questions
con.ConnectionString = constring;
SqlCommand cmdn = new SqlCommand(cmd2, con);
//SqlDataAdapter sda = new SqlDataAdapter(cmd2, conn);
try
{
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd2, con);
DataTable dtb = new DataTable();
SqlDataReader Reader = cmdn.ExecuteReader();
if (radioButton1.Checked == true)
{
Answer = radioButton1.Text;
radioButton1.Checked = false;
}
else if (radioButton2.Checked == true)
{
Answer = radioButton2.Text;
radioButton2.Checked = false;
}
else if (radioButton3.Checked == true)
{
Answer = radioButton3.Text;
radioButton3.Checked = false;
}
else if (radioButton4.Checked == true)
{
Answer = radioButton4.Text;
radioButton4.Checked = false;
}
else { Answer = ""; }
if (Answer == label3.Text)
{
MessageBox.Show("your answer is correct");
}
else
{
MessageBox.Show("your answer in incorrect");

Answers (2)