[英]Retrieving data from database as a list
我正在使用包含條件的Access數據庫處理c#程序,
我知道如何從數據庫檢索所有條件到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
顯示選定的條件。
嘗試在page_load事件中檢索組件中的條件(我猜想多列組合框或簡單的組合框會很棒),然后在用戶將對selectionchanged事件進行選擇后,使用另一個SQL函數在datagridview中顯示所選條件
它會像這樣:
這是在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 & "
希望它會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.