2013-02-28 132 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 & " 

希望它能帮上忙。