日期:2014-05-17  浏览次数:21088 次

C# 违反并发性 deletecommand影响了预期1条记录中的0条 我急死了
我是C#连接ACCESS,我表中有主键,删掉了自动编号。
运行后,出现了C# 违反并发性 deletecommand影响了预期1条记录中的0条。
我怎么都找不出,原因在哪里。求帮忙。

       private void btnDel_Click(object sender, EventArgs e)//删除
        {
            try
            {
                strSelect = "DELETE FROM " + BiaoMingID + " WHERE '红点名字'='" + redname + "'";
                
                OpenAccess(strSelect, 2);//打开连接
                string xuanze = "Select * from " + BiaoMingID;//BiaoMingID 里存着表的名字
                adObj = new OleDbDataAdapter(xuanze, oleCon);
                adObj.DeleteCommand = myCommand;//myCommand = new OleDbCommand(strSelect, oleCon);
                adObj.Fill(mydataset, BiaoMingID);
                DataTable mydatatable = mydataset.Tables[BiaoMingID];
                if (mydatatable.Rows.Count != 0)//如果行的总数不等于0
                {
                    for (int n = 0; n < mydatatable.Rows.Count; n++)
                    {
                        if (mydatatable.Rows[n][8].ToString() == (kongjian as Button).Name)
                        {   
                            mydatatable.Rows[n].Delete();
                            adObj.Update(mydataset, BiaoMingID);//这个错误。。违反并发性: DeleteCommand 影响了预期 1 条记录中的 0 条。 
                            mydataset.AcceptChanges();
                            MessageBox.Show("此记录删除成功");
                    &nbs