简体   繁体   English

从数据库中检索数据作为列表

[英]Retrieving data from database as a list

I am working on c# program with access database that contains criteria , 我正在使用包含条件的Access数据库处理c#程序,

I know how to retrieve all criteria from database to datagridview 我知道如何从数据库检索所有条件到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();  

        }

But i want to retrieve all criteria from the database as a list and let the user to choose some criteria 但是我想从数据库中检索所有条件作为列表,并让用户选择一些条件

then show the selected criteria in the datagridview . 然后在datagridview显示选定的条件。

try retrieving the criteria in a component on page_load event (i guess a multicolumncombobox or a simple combobox would be great) and then use another SQL function to show the selected criteria in the datagridview after the user will pick his desired criteria on the selectionchanged event 尝试在page_load事件中检索组件中的条件(我猜想多列组合框或简单的组合框会很棒),然后在用户将对selectionchanged事件进行选择后,使用另一个SQL函数在datagridview中显示所选条件

It will go something like this: 它会像这样:

This is on the page_load event: 这是在page_load事件上:

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

This is on SelectedIndexChanged event: 这是在SelectedIndexChanged事件上:

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

Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM