This topic is locked

preventing 2 people editing the same row

1/7/2008 1:02:19 PM
ASPRunnerPro General questions
K
kaled2006 author

Hy,
I put the same code example in event_load and before_editing and also the the type of row in my table
and he tell me "Object required"
in event load i add :[codebox]Sub EditOnLoad()

'** Custom code ****
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select IsLocked, LockTime from " & strTableName & " where " & where, dbConnection
if rs("IsLocked")=1 and DateDiff( "n", rs("LockTime"), now() )<20 then
Response.write "Record is locked. Come back later"

rstmp.close : set rstmp = nothing

Response.end
else
rstmp.close : set rstmp = nothing

dbConnection.Execute "update " & strTableName & " set IsLocked=1, LockTime=now() where " & where
end if
End Sub[/codebox]
and in before_edit :
[codebox]// Before record updated

Function BeforeEdit(dict, where, oldvalues,keys,message,inline)

' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Edit form is represented as a 'Field name'-'Field value' pair

' where - string with WHERE clause pointing to record to be edited

' oldvalues - Scripting.Dictionary object with existing data record content
'** Custom code ****
dbConnection.Execute "update " & strTableName & " set IsLocked=0, LockTime=now() where " & where
End Function' BeforeEdit[/codebox]
thank you,

K
kaled2006 author 1/8/2008

Can any one help me please

J
Jane 1/11/2008

Hi,
there is no rs object and where variable in the EditOnLoad event. Use rstmp object instead.

And add your code to Edit page: Before SQL query event:

Sub BeforeQueryEdit(strSQL,strWhereClause)

set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select IsLocked, LockTime from " & strTableName & " where " & strWhereClause, dbConnection
if rstmp("IsLocked")=1 and DateDiff( "n", rstmp("LockTime"), now() )<20 then
Response.write "Record is locked. Come back later"

rstmp.close : set rstmp = nothing

Response.end
else
rstmp.close : set rstmp = nothing

dbConnection.Execute "update " & strTableName & " set IsLocked=1, LockTime=now() where " & strWhereClause
end if
End Sub ' BeforeQueryEdit

K
kaled2006 author 1/11/2008

Thanks for help
but i get a new error about now
He tell me : [Microsoft][ODBC SQL Server Driver][SQL Server]'now' is not a recognized function name.

Sergey Kornilov admin 1/14/2008

Use getdate() instead of now().

K
kaled2006 author 1/14/2008

Thanks for your help,
The script work fine now without
When i added to the script nothing happen , I mean it not lock the IsLocked or checking if the IsLocked is already locked
even the locktime.
There is a error inside this [color=#FF0000]DateDiff( "n", rstmp("LockTime"), getdate() )<20
without it everything work great but the problem is I needed for time check.
Thank you

K
kaled2006 author 1/16/2008

Anybody can help me about correcting this line

DateDiff( "n", rstmp("LockTime"), getdate() )<20


because is not passing in the script by the way in my mssql = Locktime is datetime and my islocked is bit

L
lbragg 1/25/2008

i am trying to lock a record based on a checkbox being checked. I have made the checkbox c hecked when someone edits the record but when I have tried to set the edit befoe load event to look at the field to see if it is checked it still allows the record to be edited. Listed below is the modified code I have tried and still to to evail. Any suggestions would be appreciated. Thank You in andvance for your input.
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select review from " & strTableName & where, dbConnection
if rs("review")=yes then
Response.write "Record is locked. Come back later"

rstmp.close : set rstmp = nothing

Response.end
else
rstmp.close : set rstmp = nothing

dbConnection.Execute "update " & strTableName & " set review=yes " & where
end if