我有个问题。我无法将组合框中的选定数据保存到数据库中。任何人都可以提供任何意见或为什么会这样?
以下是使大家能够更多地了解我的问题的代码:
private void Create_LS_Load(object sender, EventArgs e)
{
using (satsEntities Setupctx = new satsEntities())
{
cbStation.DisplayMember = "StationName";
cbStation.ValueMember = "StationID";
cbStation.DataSource = Setupctx.stations.ToList();
cbLocation.DisplayMember = "LocationName";
cbLocation.ValueMember = "LocationID";
cbLocation.DataSource = Setupctx.locations.ToList();
}
}
private void btnCreate_Click(object sender, EventArgs e)
{
using (satsEntities Setupctx = new satsEntities())
{
locationstation ls = new locationstation();
ls.stationID = cbStation.SelectedIndex;
ls.locationID = cbLocation.SelectedIndex;
Setupctx.locationstations.AddObject(ls);
Setupctx.SaveChanges();
cbStation.SelectedIndex = -1;
cbLocation.SelectedIndex = -1;
MessageBox.Show("New Location Station Is Created");
}
}
任何帮助将不胜感激。谢谢!