我有一个组合框,我从数据库中的Categories Table填充了combobox项目。我使用SelectedIndexChanged事件捕获Category的id,并将CategoryId分配给id变量。但我不能正确地写出查询。 我会很高兴有人帮助我。
亲切的问候。
private void Home_Load(object sender, EventArgs e)
{
cmbCategories.DataSource = DataUtil.ExecuteReader("SELECT * FROM Categories");
cmbCategories.DisplayMember = "CategoryName";
cmbCategories.ValueMember = "CategoryId";
}
string id;
private void cmbCategories_SelectedIndexChanged(object sender, EventArgs e)
{
id = cmbCategories.SelectedValue.ToString();
bunifuCustomDataGrid1.DataSource = DataUtil.ExecuteReader($"SELECT CategoryName, ProductName, Description FROM Produts P RIGHT JOIN Categories ON P.CategoryId = C.CategoryId ={id}");
}