Another LastChanged/TimeStamp problem

Another LastChanged/TimeStamp problem

Old forum URL: forums.lhotka.net/forums/t/1294.aspx


David posted on Wednesday, September 20, 2006

I've just found a problem with the LastChanged/timestamp field when updating. Currently the generated code adds an output parameter named 'new_LastChanged' to retrieve an updated timestamp field like this:

cm.Parameters.AddWithValue("@new_LastChanged", mLastChanged)
cm.Parameters(
"@new_LastChanged").Direction = ParameterDirection.Output

This value is then read back with this:

mLastChanged = CType(cm.Parameters("@new_LastChanged").Value, Byte())

For some reason, the returned value is only 1 byte, not 8. I tested this with a varchar parameter using similar code and got the same behaviour - the return value was always trancated to one character. I assume the problem is associated with the way AddWithValue initializes space for the return value.

In Rocky's Project Tracker sample he uses this to add the parameter:

Dim param As New SqlParameter("@newLastChanged", SqlDbType.Timestamp)
param.Direction = ParameterDirection.Output
.Parameters.Add(param)

Anyway, I am currently working around this by adding the following code after the parameter is added:

cm.Parameters("@new_LastChanged").SqlDbType = SqlDbType.Timestamp

I actually do this in the user class so my generated partial class remains untouched. Can this line be added to the generated code?

 

rasupit replied on Wednesday, September 20, 2006

David,
That look like a bug, I'll make the change on c# template.
Ricky

David replied on Thursday, September 21, 2006

It's probably obvious, but I thought I should add that this also occurs when inserting a new record.

 

rasupit replied on Thursday, September 21, 2006

I have just checked in the fix to this.  Check out on CSLAContrib source code (build 6445)

Ricky

David replied on Thursday, September 21, 2006

Unfortunately I’m using VB, so I guess I'll have to wait. But thanks anyway.

Copyright (c) Marimer LLC