我面临一个关于数据库和组合框的问题。我有一个表名“站”,表内是列、站名和座位。列席设置为“BIT”。我使用组合框让用户选择“是”或“否”,但如何将它们转换为 BIT 并存储到数据库中。这是我的创建代码。
private void btnCreate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
string[] stations = StationNameList();
station creStation = new station();
creStation.Station1 = txtStation.Text;
creStation.Seat = cbSeats.SelectedItem();
if (stations.Contains(txtStation.Text))
{
MessageBox.Show("This Station is already been created. Please enter a new Station.");
}
else
{
Setupctx.stations.AddObject(creStation);
Setupctx.SaveChanges();
txtStation.Text = "";
cbSeats.SelectedIndex = -1;
MessageBox.Show("New Station Has Been Created.");
}
}
}
错误在这里:
creStation.Seat = cbSeats.SelectedItem();
他们提示我无法从字符串转换为布尔值。有什么帮助吗?