combobox.selected值无法传递给查询

时间:2014-12-10 18:33:58

标签: c# mysql winforms

我有以下查询。

MySqlDataAdapter da = new MySqlDataAdapter("SELECT RoomNo, RoomBedsNo, RoomSmoking, RoomMiniBar,RoomKitchen,RoomFirePlace,RoomBalcony, RoomVeranda, RoomGarden, RoomEntrance, RoomAirCondition, RoomTV FROM tblrooms WHERE FK_roomTypesID = '" + cboRoomType.SelectedValue + "'", conn);

问题是虽然cboRoomType.SelectedValue附近的WHERE是1.我无法获得值并填充datagrid。没有错误,只能从数据库返回任何内容。

以下代码非常完美。

MySqlDataAdapter da = new MySqlDataAdapter("SELECT RoomNo, RoomBedsNo, RoomSmoking, RoomMiniBar,RoomKitchen,RoomFirePlace,RoomBalcony, RoomVeranda, RoomGarden, RoomEntrance, RoomAirCondition, RoomTV FROM tblrooms WHERE FK_roomTypesID = '1'", conn);

这有什么不对?我不知道是否需要提供更多信息。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

SelectedValue返回一个对象,必须将其强制转换为整数。