Be careful:
i = SQL1.ExecQuerySingleResult("SELECT count(*) FROM tablename")
and
i = SQL1.ExecQuerySingleResult("SELECT MAX(autoincrement_fied) FROM tablename")
are NOT the same.
Lets take an example:
You fill a databse with 10 entries.
SELECT count(*) returns 10, number of entries.
SELECT MAX(autoincrement_fied) returns 10, max value in the autoincrement column.
Now you delete 2 enrties.
SELECT count(*) returns 8, number of entries.
SELECT MAX(autoincrement_fied) returns 10, max value in the autoincrement column.
When you delete entries the autoincrement values are NOT changed !
Best regards.