SQL timestamp column for concurrency

G

Guest

Excuse my ignornance but I am relatively new to .NET. We have migrated a
solution from Access to web based and have a fully working solution except
that we failed to consider multi-user use in ceratain areas, although
last-write is OK it has caused a few minor issues with some information being
overtyped.

Thought that we could adjust tables and VB code to work with the SQL
timestamp column but are having a few problems understanding byte/sqlbinary
declarations.

I am trying to extract the timestamp column value from SQL2000 into a
variable to display on the web form from a datareader for debugging purposes
and then use this in the where clause of our update command instead of the
rowid.

We have tried several declarations and keep receiving a CAST error For
example we get cannot cast byte() to byte on debugging the respective page.
Would be grateful if someone could point me in the right direction.

regards
 
G

Guest

Overall, it is easiest, if you are using the DataAdapter, to look at Dino
Esposito's articles on concurrency (you should be able to find them all on
msdn.microsoft.com with a short search -- sometimes easier to find using the
Google Microsoft search (http://www.google.com/microsoft.html).

By default, Update fails on lines with concurrency problems, but they are
added to the DataSet for easy retrieval. You can then show them to the user
with requeried lines and let the user decide whether or not they update.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
D

David Sceppa

A SQL timestamp is really just a byte array and, despite what its name
implies, it is not a datetime value to indicate the last time the row was
updated. That information won't help your user, but it will streamline
your updates. Use the column in your updating logic, along with the
primary key column(s) of course.

If your update succeeds, SQL Server will generate a new value for the
timestamp column. So, if you need to send multiple updates to the row from
a client, you'll need to re-fetch the server-generated timestamp value
after each successful update.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2005 Microsoft Corporation. All rights reserved.
 
J

Jay Pondy

In your SQL Stored Procedures cast the timestamp to an int type during
your selects. In your update, delete procedures pass the timestamp in
as an int parameter. From there you can either explicitly cast the
int to a timestamp or SQL Server will perform an implicit cast for
you.

From there you can handle the casted timestamp as a long on the dot
net side.

select LastName, FirstName, cast(MyTimeStampColumn as int) as
MyTimeStampColumn from Employees
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top