Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am working on a winform application where on a butoon click in a form, I have to first read the Sample table values billNo abd kotNo and then increment those values(in a single stored procedure). But the problem area is that any other user can also read the same value simultaneously, and increment those values. so resulting in two biils having same billno.

SQL
CREATE TABLE [dbo].[Sample](
    [billNo] [decimal](6, 0) NOT NULL,
    [kotNo] [decimal](6, 0) NOT NULL,
    [initials] [char](3) NOT NULL,
    [unit_code] [char](3) NOT NULL
) 



please help me to rectify my problem.

regards
Vijay
Posted
Updated 3-Jan-12 19:11pm
v2

I think this link will help you

Click Me[^]
 
Share this answer
 
First of all you should have a transaction if not already present. See: BEGIN TRANSACTION[^]

Now if this is the same table you're reading and updating, why not use a single update statement. Something like:
SQL
UPDATE MyTable
SET COL = COl + 1
WHERE ...

However, I would not store calculations in a table so consider redesigning the application to fetch the amount you're interested in at runtime. This would prevent extra logic and ensure that you always get correct results.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900