2016-06-20 62 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

相關問題