私は問題があります。コンボ ボックスから選択したデータをデータベースに保存できません。誰か意見や理由を教えてください。
私の問題についてもっと理解できるようにするコードは次のとおりです。
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");
}
}
どんな助けでも大歓迎です。ありがとう!