刪除數據我遇到由此,當用戶在刪除按鈕點擊,什麼也沒有發生問題,當我插入斷點來檢查,該selectLocStation
爲空。爲什麼會發生?任何人都可以解決我對此的疑問嗎?無法從數據庫
下面是代碼給你看我的刪除代碼。欣賞任何提供的幫助。
private void btnDel_Click(object sender, EventArgs e)
{
using (satsEntities Setupctx = new satsEntities())
{
int selectLocStation = Convert.ToInt32(cbLocStation.SelectedValue);
var DeleteRTiming =
(from delLocStation in Setupctx.requiredtimings
where delLocStation.RequiredLocationStationID == selectLocStation
select delLocStation).SingleOrDefault();
if (DeleteRTiming != null)
{
Setupctx.DeleteObject(DeleteRTiming);
Setupctx.SaveChanges();
cbLocStation.SelectedIndex = -1;
this.Edit_TS_Load(null, EventArgs.Empty);
MessageBox.Show("Selected Required Timing And " +
"The Location Station Has Been Deleted.");
}
}
}
這是用於綁定的代碼。
private void Edit_TS_Load(object sender, EventArgs e)
{
using (satsEntities Setupctx = new satsEntities())
{
var DeleteRT = (from DelRT in Setupctx.requiredtimings
join locationstationname ls in Setupctx.locationstationnames on DelRT.RequiredLocationStationID equals ls.locationstationID
select ls.locStatname).Distinct().ToList();
foreach (var locstationData in DeleteRT)
{
cbLocStation.Items.Add(locstationData);
}
}
}
孔中的結合部分,*是*那裏有'RequiredLocationStationID'的任何數據? – 2012-08-01 08:53:17
'cbLocStation.SelectedValue'的值是多少? – 2012-08-01 08:53:24
你可能會重新綁定「cbLocStation」到達click事件 – shajivk 2012-08-01 08:54:08