NOGRP90
NOGRP90

Reputation: 49

How to retrieve radio button value from database using C#

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!

Upvotes: 0

Views: 4660

Answers (1)

Dr Schizo
Dr Schizo

Reputation: 4362

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";

Upvotes: 1

Related Questions