我想知道如何使用组合框中的选定值过滤datagridview。我有多个表的数据库。
这是用于填充datagridview并将值添加到组合框中的代码:
/*OleDbCommand command1 = new OleDbCommand(query1, connection);
command1.CommandText = query1;*/
OleDbDataAdapter da1 = new OleDbDataAdapter(query_datagrid, connection);
DataSet ds = new DataSet();
//DataTable dat1= new DataTable();
da1.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.ReadOnly = true;
//
string query1 = "SELECT * FROM House";
OleDbCommand command1 = new OleDbCommand(query1, connection);
OleDbDataReader reader1 = command1.ExecuteReader();
while (reader1.Read())
{
cmbhouse.Items.Add(reader1["House_names"].ToString());
}
cmbhouse.ValueMember = "House.ID_house";
reader1.Close();
string query2 = "SELECT * FROM House";
OleDbCommand command2 = new OleDbCommand(query2, connection);
OleDbDataReader reader2 = command2.ExecuteReader();
while (reader2.Read())
{
cmbfloorhouse.Items.Add(reader2["Floors"].ToString());
cmbfloorhouse.ValueMember = "ID_house";
}
cmbfloorhouse.ValueMember = "House.ID_house";
reader2.Close();
string query3 = "SELECT TypeofHouse FROM HouseType";
OleDbCommand command3 = new OleDbCommand(query3, connection);
OleDbDataReader reader3 = command3.ExecuteReader();
while (reader3.Read())
{
cmbtypeofhouse.Items.Add(reader3[0].ToString());
}
cmbtypeofhouse.ValueMember = "HouseType.ID_type";
reader3.Close();