我遇到關於使用組合框數據的刪除問題刪除代碼。錯誤提示我我不知道如何解決它。任何人都可以幫助我呢?錯誤與使用LINQ
private void btnDel_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
var Lo = Convert.ToInt16(cbLocationData.SelectedValue);
var DeleteLocation = (from delLocation in Setupctx.locations
where delLocation.Location1 == Lo
select delLocation).Single();
Setupctx.DeleteObject(DeleteLocation);
Setupctx.SaveChanges();
this.Delete_Location_Load(null, EventArgs.Empty);
MessageBox.Show("Selected Shift Timing Has Been Deleted.");
}
}
表示我以下錯誤
算「==」不能被應用於類型「字符串」和「短」的操作數的一部分
where delLocation.Location1 == Lo
。
您的幫助將不勝感激。
您是否嘗試過單步調試代碼,以確保它進入你的foreach循環? – JohnFx 2012-07-12 03:51:09
您的活動開火你想填補cb的的SelectedIndexChanged。嘗試把它放在頁面加載或更合適的地方? – Ghost 2012-07-12 04:12:28
@Ghost感謝提醒。我將我的代碼移至Page_Load,其工作狀態非常好。 – Philemon 2012-07-12 04:21:07