1

我正在使用包含标准的访问数据库的 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.

4

1 回答 1

0

尝试在 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 & "

希望它会有所帮助。

于 2013-02-28T11:57:48.823 回答