0

I have a group box contains radio buttons eg.

o Level 1

o Level 2

How can I load value from database and check radio botton on my GUI?

private void button_clone_Click(object sender, EventArgs e)
{
    try
    {
        connection.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        command.CommandText = "SELECT * from PPAPdatabase where [PSW ID]=" + txt_c_PSW_ID.Text + "";
        OleDbDataReader dr = null;
        dr = command.ExecuteReader();                
        while (dr.Read())
        {
            comboBox_PPAP.Text = (dr["Reason"].ToString());
            checkedListBox_prodline.Text = (dr["Production Line"].ToString());                    
            checkedListBox_owner.Text = (dr["Owner"].ToString());              
            txt_comment.Text = (dr["Comment"].ToString());                                                          
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("An error has occurred: " + ex.Message,
                "Important Note",
                MessageBoxButtons.OK,
                MessageBoxIcon.Error,
                MessageBoxDefaultButton.Button1);
    }
    finally
    {
        connection.Close();
    }   

Thanks in advance!

5
  • What kind of UI, windows forms, asp.net? Commented Jun 20, 2016 at 20:25
  • What kind of data is it that you are trying to bind the radio button with? Is it a bit, string, integer column? Commented Jun 20, 2016 at 20:45
  • @BrianMains windows from application Commented Jun 20, 2016 at 21:47
  • @DrSchizo I have a column named PPAP level, and I just save the text of the levels in that colum. Commented Jun 20, 2016 at 21:51
  • Can you post how the data looks like? Do you want the radio checked if the column has anything in it, i.e. is NOT an empty string? Commented Jun 20, 2016 at 22:16

1 Answer 1

1

Assuming your radio button is called radioButton1 and the column your referring to stores values as either 1 or 0 then you would do:

radioButton1.Checked = row["PPAP"].ToString() == "1";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.