与代码误差使用LINQ删除 [英] Errors with codes for deleting using linq
本文介绍了与代码误差使用LINQ删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到关于使用组合框数据的删除的问题。错误提示我,我不知道该怎样去解决它的主意。任何人都可以帮我一下吗?
I encounter a problem regarding the deleting of data using combo box. The error prompted me I have no idea of how to solve it. Anyone can help me about it?
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.");
}
}
部分,其中delLocation。 LOCATION1 ==罗
显示我下面的错误
运营商'=='不能应用于类型的操作数'串'和'短'。
Operator '==' cannot be applied to operands of type 'string' and 'short'.
您的帮助将不胜感激。
推荐答案
创建的方法是这样的:
private void LoadLocation()
{
using (testEntities Setupctx = new testEntities())
{
var storeLocation = (from vL in Setupctx.locations
select new
{
Location1 =vL.Location1
}
);
cbLocationData.DataTextField = "Location1";
cbLocationData.DataSource = storeLocation;
cbLocationData.DataBind();
}
}
在你的页面,然后负载(ASP .NET)/形式加载(WinForm的)加:
Then on your page load(asp.net)/form Load(winform) add:
LoadLocation();
希望这有助于。
Hope this help.
问候
这篇关于与代码误差使用LINQ删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文