>Usually when a next recordnumber is generated in VFP for whatever table, the record containing the next number or even better, the whole table, is locked to prevent to 2 users to simultanously update the next nr. It's essential that the lock is placed before the update is done.
>
>How can this be done with client/server ?
>I don't want the autonumbering feature of the database server because I'm not creating a primary key (as a matter of fact, I do let create the PK by the de DBserver) but for example an invoice number that restarts at 1 every year, unless SQL allows to reset this numbering programmatically ...
lSuccess = .f.
Do While Not lSuccess
cSQL = "SELECT LastNumber FROM NumberTable WHERE cKey = 'TABLENAME'"
SQLExec(nConn, cSQL)
nLastNumber = SQLResult.LastNumber
nNewId = nLastNumber + 1
cSQL = "UPDATE NumberTable SET LastNumber = nNewID WHERE "+ ;
"cKey='TABLENAME' and LastNumber = nLastNumber"
lSuccess = ( SQLExec(nConn, cSQL) = 1 )
EndDo
You will want to also check the resule of the first query, cause if it fails you could be in this loop for a while.
BOb