user2119170
user2119170

Reputation: 21

Retrieving data from database as a list

I am working on c# program with access database that contains criteria ,

I know how to retrieve all criteria from database to 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.

Upvotes: 1

Views: 251

Answers (1)

SalemRady
SalemRady

Reputation: 191

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

It will go something like this:

This is on the page_load event:

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:

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

Hope it will help.

Upvotes: 0

Related Questions