【发布时间】:2012-07-11 18:47:55
【问题描述】:
我遇到了关于使用组合框删除数据的问题。该错误提示我不知道如何解决它。有人可以帮我吗?
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 循环?
-
您的事件在您尝试填充的 cb 的 SelectedindexChanged 上触发。试试把它放在页面加载或更合适的地方?
-
@Ghost 谢谢提醒。我将我的代码移到 Page_Load 并且它工作得很好。
-
我认为您将代码放在错误的位置.. 我同意@Ghost