数据更新时出现同步错误,如何解决呢? 数据适配器更新数据时,where后面并非是主键,而是所有的原始字段值。当在更新前,有其它的系统对该记录修改后,这条where语句将不能选中任何行,所以出现了同步错误并非你所说的锁。多用户情况下,用锁是比较好的解决方案 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 同意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; } } 我的一点小问题 Oracle:求一条sql语句? C# 修改文本文件里的内容 TreeView 如何从SQL数据库中获取图片 问在C#中Equals与==的区别? 文件名问题. 求教个C#局域网发送邮件 或是聊天 请教如何让多个窗体共用一个oledbconnection 两个问题(1)datagrid传参问题;(2)datalist分页的实现 散分...近日要闭关研究WMI 怎样实现事务?
/// <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;
}
}