Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in locking rows in database

Status
Not open for further replies.

Bitaoo

Programmer
Dec 18, 2002
81
US
Hello,

I have a locking problem that I cannot underestand it. Would you please help me to find the problem?
I appreciate your help in advance. I ahev a table named T1 with the following columns:

Id --> Int primary key
Name --> Char(10)
R_Id --> Int
ValCol --> Int
Choice --> Int


and here is my code:

sub main
call Open_DB(cn)
call Begin_Transaction(cn)

set cmd.commandText = "Insert into T1(Name, R_Id, ValCol, Choice) Values ('B1', 1, 8, 1)
cmd.execute ' Insert a row in database

set cmd.commandText = "update T1 set Choice = 1 where R_Id = 1"
cmd.execute ' Update many rows in table T1

rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.open "Select * from T1 Where R_Id = 1"
do until rs.EOD
cmd.commandText = "Update T1 Set ValCol = 12 Where Id = " & rs("Id").value
cmd.execute ' Here I have problem, The row in locked and I cannot upddate it. (TimeOut Expired)

rs.movenext
loop
rs.close

call Commit_transaction(cn)
call db_close(cn)
end sub

The problem is the Update in the loop. would you please help me.
--Bita
 
Try resetting the command object with each iteration of the loop.

Code:
...
do until rs.EOD
      [b]Set[/b] cmd.commandText = ...
...

Or using a separate set statement,

Code:
...
do until rs.EOD
     Set cmd = New ADODB.Command
     cmd.commandText = ...
...


zemp
 
Thanks, but it doesn't work. :(

--Bita
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top