2011-04-21 3 views
0

이 다음 생성 된 데이터 어댑터입니다 :질문에 데이터 어댑터 (UpdateCommand)

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)"; 
  1. 이 공식적인 정의에 따라 낙관적 동시성을 구현 where 절인가?

  2. 내 생각에 SELECT의 목적은 업데이트 된 행의 수를 반환하는 것이지만 COUNT (*)를 사용하지 않는 이유는 무엇입니까?

업데이트 : 여기 생성 된 업데이트 코드는 (2)에서 SELECT에 대한 아이디어를 제공합니다. 해당 쿼리가 무엇

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(); 
    } 
    } 
} 

답변

2

은 갱신 전 상태의 대신에, 당신이 메모리의 개체를 업데이트하도록, 다시 나중에 사용하기 위해 응용 프로그램에 업데이트 된 레코드를 반환합니다. 기본적으로 왕복 1 회에 UPDATE xxx WHERE [email protected]SELECT xxx FROM xxx WHERE [email protected] 명령입니다.

+0

생성 된 업데이트에서 ExecuteNonQuery를 호출하는 코드를 추가했습니다 ... SQL은 다른 곳에서는 참조 할 수없는 ... –

1

where 절이 정의에 따라 낙관적 동시성을 구현합니까? 의

정렬. 모든 열이 하나라도 변경되었는지 확인하기 위해 모든 열을 확인하고 있습니다. 레코드가 변경된 경우 업데이트되지 않습니다.

그러나 Wikipedia의 한 정의에 따르면 레코드가 변경되면 트랜잭션이 롤백됩니다. 그것은 여기서 일어나지 않습니다.

관련 문제