Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I want to match the selected radio button answer in database quiz app

Aimen AwanAimen Awan Member Posts: 1
in C#

there are optS on form i want is to match the selected radiobutton with answer column in database .. also it shud match on the basis of question like what question it was (obviously) and if selected radiobutton is the answer it shud update the score this wat i have donE
`bool correct = false;

       Option1 = radioButton1.Text;
        Option2 =radioButton2.Text;
        Option3 = radioButton3.Text;
        Option4 = radioButton4.Text;
        conn.ConnectionString = constring;


        string Query = "SELECT Answer FROM Questions where Difflevel='" + DiffLevel.Text + "' AND SubName='" + subj.Text + "'"; //difflevel n subname r comboboxes
            SqlCommand cmd = new SqlCommand(Query, conn);

        try
        {
                  SqlDataAdapter sda = new SqlDataAdapter(Query, conn);
            DataTable dt = new DataTable();
            conn.Open();
            sda.Fill(dt);

            SqlDataReader theReader = cmd.ExecuteReader();

            while (theReader.Read())
            {


                if (radioButton1.Checked ||radioButton2.Checked || radioButton3.Checked ||radioButton4.Checked)
                    {

                        Option1 = (theReader["Answer"].ToString());
                        Option2= (theReader["Answer"].ToString());
                        Option3= (theReader["Answer"].ToString());
                        Option4= (theReader["Answer"].ToString());


                    else 
                    {
                        correct = true;
                    }




                    }
                }

            if (correct)
            {

                MessageBox.Show("right answer");
                score = score + 1;

                label2.Text = score.ToString();


            }
           else
            {
                 MessageBox.Show("wrong answer");


            }
            }
        catch (Exception exp)
        {
            MessageBox.Show(exp.ToString());
        }
        finally
        {
            conn.Close();
        }


    }


  }









        }`its just sayin wrong answer even the answer is correct and say right when answer is wrong .. and sometimes work fine right for right and wrong for wrong ... but bug is there ... also plz tell me where its going wrong in my code and where should i alter it ? thnxx 
Sign In or Register to comment.