我正在面對有關數據庫和組合框的問題。我得到了一個表名「站」,桌子內有列,站名和座位。列座位設置爲「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();
他們提示我不能從字符串爲bool轉換。 有什麼幫助嗎?
使用條件,如果是設置1否則爲0 – 2012-07-18 06:57:21