[英]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.