并发冲突:UpdateCommand 影响 0 个记录,看了很多帖子,没有发现解决了的。没有高手了吗
原代码如下:
public bool UpdateUpLoadDV(DataSet upLoadDV)
{
dsCommand = new OleDbDataAdapter();
//dsCommand.SelectCommand = new OleDbCommand();
//dsCommand.SelectCommand.Connection = new OleDbConnection(dvConnectString.ConnectionString);
//dsCommand.TableMappings.Add("Table", UpLoadDVInfo_TABLE);
if ( dsCommand == null )
{
throw new System.ObjectDisposedException( GetType().FullName );
}
//
// Get the command and update the database
//
dsCommand.UpdateCommand = GetUpdateCommand();
dsCommand.Update(upLoadDV,UpLoadDVInfo_TABLE);
//
// Check for table errors to see if the update failed.
//
if (upLoadDV.HasErrors )
{
upLoadDV.Tables[UpLoadDVInfo_TABLE].GetErrors()[0].ClearErrors();
return false;
}
else
{
upLoadDV.AcceptChanges();
return true;
}
}
//获得UpdateCommand得函数
private OleDbCommand GetUpdateCommand()
{
OleDbParameter parm;
if ( updateCommand == null )
{
updateCommand = new OleDbCommand("UPDATE UpLoadDVInfo SET iDI_IsChecked = @iDI_IsChecked,cDI_FileNameOld = @cDI_FileNameOld,cDI_ImageFileName =@cDI_ImageFileName WHERE iDI_ID =@iDI_ID " ,new OleDbConnection(dvConnectString.ConnectionString));
//
// Construct the command since we don't have it already
//
updateCommand.CommandType = CommandType.Text;
OleDbParameterCollection oleDbParams = updateCommand.Parameters;
parm = oleDbParams.Add(new OleDbParameter(iDI_ID_PARM,OleDbType.Integer));
oleDbParams.Add(new OleDbParameter(iDI_IsChecked_PARM,OleDbType.Integer));
oleDbParams.Add(new OleDbParameter(cDI_FileNameNew_PARM, OleDbType.VarChar, 200));
oleDbParams.Add(new OleDbParameter(cDI_FileNameOld_PARM, OleDbType.VarChar, 200));
oleDbParams.Add(new OleDbParameter(cDI_ImageFileName_PARM, OleDbType.VarChar, 200));
//
// Define the parameter mappings from the data table in the
// dataset.
//
oleDbParams[iDI_ID_PARM].SourceColumn = iDI_ID_FIELD;
oleDbParams[iDI_IsChecked_PARM].SourceColumn = iDI_IsChecked_FIELD;
oleDbParams[cDI_FileNameNew_PARM].SourceColumn = cDI_FileNameNew_FIELD;
oleDbParams[cDI_FileNameOld_PARM].SourceColumn = cDI_FileNameOld_FIELD;
oleDbParams[cDI_ImageFileName_PARM].SourceColumn = cDI_ImageFileName_FIELD;
parm.SourceVersion = DataRowVersion.Original;
}
return updateCommand;
}
其中,iDI_ID是自增字段。也是关键字段,
UPDATE UpLoadDVInfo SET iDI_IsChecked = @iDI_IsChecked,cDI_FileNameOld = @cDI_FileNameOld,cDI_ImageFileName =@cDI_ImageFileName WHERE iDI_ID =@iDI_ID
这个语句如果写成
UPDATE UpLoadDVInfo SET iDI_IsChecked = @iDI_IsChecked WHERE iDI_ID =@iDI_ID
没有问题,可以更新。但是更新2个以上字段就并发冲突了。
在线等候,希望能解决。