I want to lock a record and don't let the user

Results 1 to 2 of 2

Thread: I want to lock a record and don't let the user

  1. #1
    Join Date
    Dec 1969

    Default I want to lock a record and don't let the user

    I&#039d like to lock a record when a user is updating it. What can I do? I think it&#039s not so difficult but I really got no idea

  2. #2
    Join Date
    Dec 1969

    Default RE: I want to lock a record and don't let the

    &nbsp;<BR>Is the user updating via a form on a web page?<BR>If so then maybe locking is not a good idea at that point. What happens if the user leaves their browser on the form and does not commit the transaction?<BR><BR>I&#039ve made use of a LastAmend date on records. You read the record without locking, display in a form for editing including the LastAmend date as a hidden field. Don&#039t lock the record until the last minute, i.e in the asp page which performs the update. At this point the asp will have to check the LastAmend date on the record that it locks against the LastAmend date sent from the form - if different then another user has tried to amend the record at the same time so just dispaly a warning and get the user to requery the record before amending.<BR><BR>The chances that 2 users would try and lock the the same record at exactly the same time (we&#039re probably talking down to the second or milisecond even) are negligible and you can code an "On Error" type subroutine to deal with that.<BR><BR>To lock the record for updating use something like this....<BR><BR><BR>Set oRs.ActiveConnection = objConnection <BR>oRs.Source = "SELECT * FROM myTable WHERE ID=" = Request.form("ID")<BR>oRs.CursorType = adOpenStatic<BR>oRs.LockType = adLockOptimistic<BR>oRs.Open<BR><BR>oRs("myField") = Request.form("myField")<BR>&#039 etc etc.....<BR><BR>oRs.Update<BR><BR><BR>I&#039m assuming oRs is your record set and objConnection the active db connection<BR><BR><BR>(thanks to this forum for coming up with this idea when I asked a similar question - it works very well!)<BR><BR><BR>hope this helps<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts