【发布时间】:2019-05-12 23:45:17
【问题描述】:
我在网上找不到我的问题的答案..
我有一个使用 LINQ(存储过程)填充 SQL 表的 ListBox
我有一个 ComboBox,它也使用 LINQ(存储过程)填充了一条 SQL 语句 问题是 ComboBox 的存储过程需要来自 ListBox 的输入,而我似乎无法正确转换它。
这是我的 ListBox 的填充方式:
private void NouvelleReservation2_Load(object sender, EventArgs e)
{
ExamenSGBDEntities oExamenSgbdEntities = new ExamenSGBDEntities();
listBoxRestaurant.DataSource = oExamenSgbdEntities.SelectAllRestaurants();
listBoxRestaurant.DisplayMember = "RESTO";
listBoxRestaurant.ValueMember = "idRestaurants";
listBoxRestaurant.SelectedIndex = 0;
}
这是我的 ComboBox 的填充方式:
private void listBoxRestaurant_SelectedIndexChanged(object sender, EventArgs e)
{
ExamenSGBDEntities oExamenSgbdEntities = new ExamenSGBDEntities();
comboBoxTables.DataSource =
oExamenSgbdEntities.SelectTablesByRestaurant(listBoxRestaurant.Items.Cast<Restaurant>()); //Here is where i'm struggling... I need to give the "idRestaurant" from the ListBox as parameter for my stored procedure.
comboBoxTables.DisplayMember = "TABLECHAISE";
comboBoxTables.ValueMember = "idTables";
}
我尝试在 DataRowView 中转换 selectedItem,然后再转换为整数,但没有成功。 已尝试您现在在代码中看到的内容,但无法使其正常工作。
有人可以帮帮我吗?
提前致谢!
【问题讨论】:
标签: c# winforms linq combobox listbox