This time, there's a project ID that has frequent ID collisions. I couldn't find a reason for that. Save the ID to the new ID
On the code look at the big God pointing under
<summary>
To the maximum ID in the table
</summary>
<param name= "fld" > Field name--Must be int type </param>
<param name= "tbl" > table name </param>
<param name= "qrytmp" > Temporary data set </param>
<param name= "Rdtype" > Fields </param>
<returns></returns>
function Tmainform.getmaxid (FLD, tbl:string; qrytmp:tadoquery; rdtype:string): string;
Var
S, CId, ccondition:string;
Begin
Ccondition: = ' where Crdtype = ' + quotedstr (rdtype);
S: = ' Select IsNull (max (' + fld + '), 0) +1 from ' + tbl;
If Rdtype <> ' then
S: = s + ccondition;
Doquery (Qrytmp, S, true);
CID: = qrytmp. Fields[0]. asstring;
S: = ' select count (1) from ' + tbl;
If Rdtype <> ' then
S: = s + ccondition;
Doquery (qrytmp, s);
If Rdtype <> ' then
Begin
If Qrytmp. Fields[0]. Asinteger <= 0 Then
Begin
s: = ' Insert Yq_getmaxid (CRDTYPE,CMAXID) VALUES ('
+ QUOTEDSTR (rdtype) + ', ' + cid + ') ';
Doquery (Qrytmp, S, false);
End Else
Begin
S: = ' update yq_getmaxid set cmaxid = ' + cid + ccondition;
Doquery (Qrytmp, S, false);
End
End
Result: = CID;
End
YQ_GETMAXID is a temporary table built.
As follows:
CREATE TABLE Yq_getmaxid
(
ID int identity PRIMARY key,
Crdtype nvarchar (+) default ',--out of storage type
CMAXID int Default 0-This place should start with I
)
Execute the SQL statement as follows:
<summary>
Execute SQL statement
</summary>
<param name= "Adoquery" > Datasets </param>
<param name= "strSQL" >sql statement </param>
<param name= "bopen" > whether to execute open</param>
Procedure Tmainform.doquery (var adoquery:tadoquery; strsql:string; bopen:boolean);
Begin
Adoquery.close;
Adoquery.sql.clear;
Adoquery.sql.add (strSQL);
If Bopen Then
Begin
Adoquery. Open;
End Else
Adoquery. Execsql;
End
Delphi Concurrent Fetch Database ID problem