2016-06-20 13 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どのような種類の、窓の形、asp.netの? –

+0

ラジオボタンをバインドしようとしているのはどのような種類のデータですか?ビット、文字列、整数列ですか? –

+0

@BrianMainsアプリケーションのアプリケーション – NOGRP90

答えて

1

と仮定すると、あなたのラジオボタンがradioButton1と呼ばれ、あなたはどちらか1または0として保存する値を参照列には、あなたはどうなる:

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

ありがとうございます。できます! – NOGRP90

関連する問題