Zhaky 0 Newbie Poster

I need to bind three radio buttons to three different columns in a table from access database. What code do I need? This is the code in my DBConnection class:

public static List<Answers> LoadAnswers()
        {
            List<Answers> answers = new List<Answers>();
            OleDbConnection myConnection = GetConnection();

            string myQuery = "SELECT * FROM Answers";
             OleDbCommand myCommand = new OleDbCommand(myQuery, myConnection);

            try
            {
                
              myConnection.Open();
              OleDbDataReader reader = myCommand.ExecuteReader();

              while (reader.Read())
              {
              Answers a = new Answers(Int32.Parse(reader["ID"].ToString()),
                                                       reader["AnswerA"].ToString(),
                                                       reader["AnswerB"].ToString(),
                                                       reader["AnswerC"].ToString(), 
                                                      (Int32.Parse(reader["QuestionId"].ToString())));
              answers.Add(a);
              }

              return answers;
    }
              catch (Exception ex)
            {
                Console.WriteLine("Exception in DBHandler" + ex);
                return null;
            }
            finally
            {
                myConnection.Close();
            }         
    }

I need one radio button for field AnswerA, one radio button for - AnswerB and another one for AnswerC. This is an online test project, so the information for the radio buttons should be loaded in the same order the questions are loaded (Questionld).I've tried to use radioButtonList, but it does not work, as I can't identify the separate radio buttons. This is the code I used:

rbListAns.DataSource = DatabaseConnecter.LoadAnswers();
           rbListAns.DataTextField = "AnswerA";
           rbListAns.DataTextField = "AnswerB";
           rbListAns.DataTextField = "AnswerC";
           rbListAns.DataValueField = "QuestionId";
           rbListAns.DataBind();

I am a C# beginner and would truly appreciate your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.