如何使用 C# 从数据库中检索单选按钮值
How to retrieve radio button value from database using C#
我有一个包含单选按钮的组框,例如
o Level 1
o Level 2
如何从数据库加载值并检查我的 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();
}
提前致谢!
假设您的单选按钮名为 radioButton1
,并且您引用的列将值存储为 1
或 0
,那么您将执行:
radioButton1.Checked = row["PPAP"].ToString() == "1";
我有一个包含单选按钮的组框,例如
o Level 1
o Level 2
如何从数据库加载值并检查我的 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();
}
提前致谢!
假设您的单选按钮名为 radioButton1
,并且您引用的列将值存储为 1
或 0
,那么您将执行:
radioButton1.Checked = row["PPAP"].ToString() == "1";