Timestamp problem
Old forum URL: forums.lhotka.net/forums/t/2944.aspx
toddb1389 posted on Thursday, May 24, 2007
I'm working on my first
CSLA app and I'm getting a "Row edited by
another user" error when I update an object. The relevant code is:
In DataPortal_Update:
cm.Parameters.Add("@
lastChanged",
SqlDbType.Timestamp);
cm.Parameters["@
lastChanged"].Value = _timestamp;
In DataPortal_Fetch:
dr.
GetBytes("
LastChanged", 0, _timestamp, 0, 8);
In Stored Procedure:
SET
...
WHERE
BookId = @id
AND
LastChanged = @
lastChanged
IF @@ROWCOUNT = 0
RAISERROR('Row has been edited by another user', 16,1)
This post:
http://forums.lhotka.net/forums/thread/8053.aspx mentions
the same problem and I adjusted my code in DataPortal_Update to
explicitly set the
datatype of the parameter, as suggested, but I still
get the 'Row has been edited by another user' error. The database is Sql Server Express.
Any ideas?
By the way, Rocky -- I enjoyed the book and really like working with the framework so far.
dcleven replied on Friday, May 25, 2007
I think you need to set the direction of the parameter as an InputOutput, like this:
SqlParameter param = new SqlParameter("@NewTimeStamp", SqlDbType.Timestamp);
param.Direction = ParameterDirection.InputOutput;
param.Value = m_timestamp;
cm.Parameters.Add(param);
cm.ExecuteNonQuery();
m_timestamp = (byte[])cm.Parameters["@NewTimeStamp"].Value;
The above code works for me ![Smile [:)]](/emoticons/emotion-1.gif)
--Doug
toddb1389 replied on Monday, May 28, 2007
That did the trick. Thanks Doug!
Copyright (c) Marimer LLC