首页 新闻 会员 周边 捐助

LINQ TO SQL 删除操作时报错“找不到行或行已更改”

0
[已解决问题] 解决于 2012-10-30 17:58

表所有字段为非空

加载ID主键

protected void Page_Load(object sender, EventArgs e)
    {
        HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext();
       ENTUserAccount useraccount= db.ENTUserAccount.Single(ua => ua.WindowsAccountName == @"VARALLO1\VaralloMadison");

       ViewState["ENTUserAccountID"] = useraccount.ENTUserAccountID;
          }

 

执行删除:

 protected void Button4_Click(object sender, EventArgs e)
    {
        HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext();
        try
        {
            db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
        }

        catch (System.Data.Linq.ChangeConflictException ex)
        {
            foreach (System.Data.Linq.ObjectChangeConflict occ in db.ChangeConflicts)
            {
                occ.Resolve(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
            }
        }
        ENTUserAccount useraccount = new ENTUserAccount();

        useraccount.ENTUserAccountID = Convert.ToInt32(ViewState["ENTUserAccountID"]);
      

        db.ENTUserAccount.Attach(useraccount);
        db.ENTUserAccount.DeleteOnSubmit(useraccount);
        db.SubmitChanges();//此处报错“找不到行或行已更改”

    }

没做更新,是否删除也要添加时间戳?

圆 豆的主页 圆 豆 | 初学一级 | 园豆:112
提问于:2012-10-30 14:52
< >
分享
最佳答案
0

晕,不出所料,要添加Version字段的!

圆 豆 | 初学一级 |园豆:112 | 2012-10-30 16:59
其他回答(1)
0

是不是这行已经更改了啊 db.ENTUserAccount.DeleteOnSubmit(useraccount);

chenping2008 | 园豆:9836 (大侠五级) | 2012-10-30 15:01

没有更改只做过插入操作,我想把插入的删除了,才发现这个问题,插入的代码如下:

 protected void Button1_Click(object sender, EventArgs e)
    {
        HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext();

        ENTUserAccount useraccount = new ENTUserAccount
        {
            WindowsAccountName = @"VARALLO1\VaralloMadison",
            FirstName = "Madison",
            LastName = "Varallo",
            Email = "madison.varallo@v2.com",
            IsActive = true,
            InsertDate = DateTime.Now,
            InsertENTUserAccountID = 1,
            UpdateDate = DateTime.Now,
            UpdateENTUserAccountID = 1
        };

        db.ENTUserAccount.InsertOnSubmit(useraccount);
        db.SubmitChanges();

支持(0) 反对(0) 圆 豆 | 园豆:112 (初学一级) | 2012-10-30 15:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册