使用 linq 删除的代码错误 [英] Errors with codes for deleting using linq

查看:22
本文介绍了使用 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.");
    }
}

部分 where delLocation.Location1 == Lo 显示以下错误

运算符=="不能应用于string"和short"类型的操作数.

Operator '==' cannot be applied to operands of type 'string' and 'short'.

非常感谢您的帮助.

推荐答案

创建一个类似这样的方法:

Create a method something like this:

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();

        }
}

然后在你的页面 load(asp.net)/form Load(winform) 添加:

Then on your page load(asp.net)/form Load(winform) add:

           LoadLocation();

希望对您有所帮助.

问候

这篇关于使用 linq 删除的代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆