ADO - Retrieve and update values
- From: "IanJ" <ijohansson@xxxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 10:01:49 +0100
Hi,
D5, WinXP, SQLServer 2000, MDAC 2.7
I have a table with one row that contains key values for other tables. To
get the next key value I query the table, store the key value, close the
query. I then use another query to update the table with an incremented
value as the next available key. The code is shown below (uses ADO)
try
// Retrieve id value
DM.qryKey.Close;
DM.qryKey.Open;
DM.PeopleId := DM.qryKey.FieldByName('people').Value;
DM.qryKey.Close;
// Increment id value for next tme
DM.qryGP.Close;
DM.qryGP.SQL.Clear;
DM.qryGP.SQL.Add('UPDATE FI_KEYS SET people =
'+IntToStr((DM.PeopleId+1)));
DM.qryGP.ExecSQL;
except
ShowMessage('Unable to retrieve an ID number'+#13#10+
'Case details have NOT BEEN SAVED'+#13#10+
#13#10+'Click Save to try again');
DM.PeopleId := -1;
end;
On occasions (it appears to be random) the above code doesn't work and the
'except' block is executed but one of the queries appears to lock and
remains 'locked' no matter how often you retry. The application has to be
closed before the code works again.
I'm fairly new to this stuff but could anyone see why the above would
occasionally lock or suggest a better way of retrieving a value and then
updating it (for a variety of reasons, I can't use an autoinc \ identity
number type).
Many thanks
Ian
.
- Follow-Ups:
- Re: ADO - Retrieve and update values
- From: IanJ
- Re: ADO - Retrieve and update values
- From: Vitali Kalinin
- Re: ADO - Retrieve and update values
- From: Guillem
- Re: ADO - Retrieve and update values
- Prev by Date: Re: Refresh of a DBGrid
- Next by Date: Re: ADO - Retrieve and update values
- Previous by thread: Re: Windows has no MS Access installed
- Next by thread: Re: ADO - Retrieve and update values
- Index(es):
Relevant Pages
|