2016-06-20 145 views
0

我有一个组框包含单选按钮,例如。如何从数据库检索单选按钮值使用C#

O级1

O级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(); 
    } 

在此先感谢!

+0

UI什么样的,Windows窗体,asp.net? –

+0

你试图绑定单选按钮的是什么样的数据?它有点,字符串,整数列? –

+0

@BrianMains从应用程序的窗口 – NOGRP90

回答

1

假设您的单选按钮被称为radioButton1和你指的是存储值都用10列,那么你会怎么做:

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

谢谢。有用! – NOGRP90

相关问题