以下是来自生成的数据适配器的内容:
this._adapter.UpdateCommand.CommandText = @"
UPDATE [dbo].[Currency2] SET [cid1] = @cid1, [cid2] = @cid2, [m] = @m
WHERE (([id] = @Original_id)
AND ([cid1] = @Original_cid1)
AND ([cid2] = @Original_cid2)
AND ([m] = @Original_m));
SELECT id, cid1, cid2, m
FROM Currency2
WHERE (cid1 = @cid1) AND (cid2 = @cid2) AND (id = @id)";?
Update:这是生成的更新代码,它为我提供了关于SELECT in (2)的想法。
public virtual int Update(int cid1, int cid2, decimal m, int Original_id, int Original_cid1, int Original_cid2, decimal Original_m, int id) {
this.Adapter.UpdateCommand.Parameters[0].Value = ((int)(cid1));
this.Adapter.UpdateCommand.Parameters[1].Value = ((int)(cid2));
this.Adapter.UpdateCommand.Parameters[2].Value = ((decimal)(m));
this.Adapter.UpdateCommand.Parameters[3].Value = ((int)(Original_id));
this.Adapter.UpdateCommand.Parameters[4].Value = ((int)(Original_cid1));
this.Adapter.UpdateCommand.Parameters[5].Value = ((int)(Original_cid2));
this.Adapter.UpdateCommand.Parameters[6].Value = ((decimal)(Original_m));
this.Adapter.UpdateCommand.Parameters[7].Value = ((int)(id));
global::System.Data.ConnectionState previousConnectionState = this.Adapter.UpdateCommand.Connection.State;
if (((this.Adapter.UpdateCommand.Connection.State & global::System.Data.ConnectionState.Open)
!= global::System.Data.ConnectionState.Open)) {
this.Adapter.UpdateCommand.Connection.Open();
}
try {
int returnValue = this.Adapter.UpdateCommand.ExecuteNonQuery();
return returnValue;
}
finally {
if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) {
this.Adapter.UpdateCommand.Connection.Close();
}
}
}发布于 2011-04-21 01:23:42
该查询所做的是,将更新后的记录返回应用程序以供以后使用,以便在内存中有更新的对象,而不是更新前的状态。基本上是一次往返中的UPDATE xxx WHERE ID=@ID和SELECT xxx FROM xxx WHERE ID=@ID命令。
发布于 2011-04-21 02:23:12
是where子句根据其正式定义实现乐观并发性吗?
说大也大吧。它正在检查每一列,看看是否有人更改了其中任何一列。如果记录已经更改,则不会更新。
然而,一个定义(来自维基百科)表示,如果记录已经更改,事务将被回滚。这不是在这里发生的。
https://stackoverflow.com/questions/5738438
复制相似问题