Re: Update a record in SQL Database from C#.NET
From: Mihaly (Mihaly_at_discussions.microsoft.com)
Date: 12/31/04
- Next message: Ray Alirezaei: "Re: copy and paste from webpage dosn't work in IDE"
- Previous message: Le, Thanh-Nhan: "Re: print text or content of a control"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 31 Dec 2004 01:59:01 -0800
I thinked to this solution, but I tried an other. When the user begin the
update, I begin a transaction with isolation level read committed and read
the record. Then the user change the record's date and saves the changees.
When the user saves the new values I do the update and the commit transaction.
In this case I can read the record which was not updated and I can update
the record after the first user updated it.
If I use the isolation level serializable, I get the good solution, but
if the user which was read first the record is too slow, he blocks the other
users.
The best solution is with timestamp? In this case I need a timestamp
field in any table.
Thank you for help and I wish you a Happy New Year!
Mihaly
"Ken Allen" wrote:
> SQ Server supports a data type called TIMESTAMP that can be used
> specifically for this purpose. You do not have to specify a value for
> fields that are of this type; the database will automatically assign a
> value each time a record is created or updated.
>
> Ensure that you retrieve this column with your query, and ensure that
> you include it in the WHERE clause of the update. You can use this
> approach whether you are building your own UPDATE statement or if you
> are using the Update() method on the DataAdapter object.
>
> Note that you should always check the return value from the execution of
> the UPDATE statement or the Update() method call to ensure that the
> proper number of records have been modified. If the record was changed,
> then the count will be zero; leave this out and a malformed request may
> update more than one record. For that reason it is often best to wrap
> these updates in a transaction so that you can roll back the attempt in
> case of a detected error.
>
> -Ken
- Next message: Ray Alirezaei: "Re: copy and paste from webpage dosn't work in IDE"
- Previous message: Le, Thanh-Nhan: "Re: print text or content of a control"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|