简体   繁体   中英

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!

假设您的单选按钮称为radioButton1并且您引用的列将值存储为10那么您将执行以下操作:

radioButton1.Checked = row["PPAP"].ToString() == "1";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM