2013-02-28 108 views
1

我的工作在C#程序與包含標準的Access數據庫,檢索從數據庫中的數據作爲一個列表

我知道如何從數據庫中檢索所有標準datagridview

 OleDbCommand command = new OleDbCommand(); 
     command.Connection = connect; 
     command.CommandText = "SELECT Criteria FROM ERPs"; 

     OleDbDataReader reader = command.ExecuteReader(); 

     while (reader.Read()) 
     { 
      dataGridView1.Rows.Add(); 

      dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Criteria"].Value = reader[0].ToString(); 

     } 

但我想找回從數據庫中的所有條件列表並讓用戶選擇一些條件

然後在datagridview中顯示所選標準。

+0

http://www.whathaveyoutried.com – Vogel612 2013-02-28 11:39:09

+1

我不明白。您創建列表時遇到問題嗎?或者將該列表綁定到Listcontrol或Datagrid或使用Multiselect? – 2013-02-28 11:42:39

+0

創建列表,並且用戶從該列表中選擇,用戶從該列表中選擇的項目出現在datagridview中 – user2119170 2013-02-28 11:56:45

回答

0

嘗試檢索page_load事件上的組件中的條件(我猜一個multicolumncombobox或一個簡單的組合框會很好),然後使用另一個SQL函數在用戶將選擇他想要的標準之後在datagridview中顯示選定的條件SelectionChanged事件

它會是這樣的:

這是在Page_Load事件:

command.CommandText = "SELECT ID, Criteria FROM ERPs" 
'the display member will be the criteria and the value will be the id 

這是SelectedIndexChanged事件:

command.CommandText = "SELECT Criteria FROM ERPs WHERE ID=" & ComboBox1.selectedvalue & " 

希望它能幫上忙。