数据适配器更新数据时,where后面并非是主键,而是所有的原始字段值。当在更新前,
有其它的系统对该记录修改后,这条where语句将不能选中任何行,所以出现了同步错误
并非你所说的锁。
多用户情况下,用锁是比较好的解决方案

解决方案 »

  1.   

    同意gujunyan(ivy) ,建议你Update过程使用事务和锁.给你个例子;
    /// <summary>
    /// 更新数据库
    /// </summary>
    public bool DataUpdate()
    {
    oleDbDA_rohj.InsertCommand=oleDbCB_rohj.GetInsertCommand(); 
    oleDbDA_rohjdetail.InsertCommand=oleDbCB_rohjdetail.GetInsertCommand();
    OleDbTransaction oleDbTr=Cls_D_Config.olegCn.BeginTransaction();
    try
    {
    string pr_no="";
    oleDbCmd.Connection=Cls_D_Config.olegCn; 
    oleDbCmd.CommandText="select * from fz_ro_hj_recipe_wastebook with (TABLOCKX) ";
    oleDbCmd.Transaction=oleDbTr; 
    pr_no="0000"+Cls_System.dr_id;
    pr_no=pr_no.Substring(pr_no.Length-4);
    pr_no=pr_no+Convert.ToString(Convert.ToInt32(oleDbCmd.ExecuteScalar())+1); 
    foreach(DataRow DR in TempDS.Tables["rohjdetail"].Rows)
    {
    DR["pr_no"]=pr_no;
    }
    foreach(DataRow DR in TempDS.Tables["rohj"].Rows)
    {
    DR["pr_no"]=pr_no;
    }
    oleDbDA_rohj.InsertCommand.Transaction=oleDbTr;  
    oleDbDA_rohj.Update(TempDS,"rohj");
    oleDbDA_rohjdetail.InsertCommand.Transaction=oleDbTr; 
    oleDbDA_rohjdetail.Update(TempDS,"rohjdetail"); 
    oleDbCmd.CommandText="update fz_ro_hj_recipe_wastebook set pr_no_max='"+pr_no.Substring(pr_no.Length-8)+"'";
    oleDbCmd.Transaction=oleDbTr; 
    oleDbCmd.ExecuteNonQuery();
    oleDbTr.Commit();
    MessageBox.Show("存盘成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
    return true;
    }
    catch(Exception ex)
    {
    oleDbTr.Rollback();
    MessageBox.Show(ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);   
    return false;
    }
    }