Returns the maximum number of a table.

Source: Internet
Author: User
Maximum number of tables: Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiBase/html/delphi_20061210224437206.html
Why is there no value I found out...

Paste your statement, OK?

Query3. SQL. Add ('select max (ID) as maxid from userload ');
Query3.open;
T: = query3.fieldvalues ['maxid'];

This is the key part, and I assign a value to other variables, which means that I am a null value... however, when there is a record in the table, there will be no error. If there is no record, there will be an error ~

Query3. SQL. Add ('select max (ID) as maxid from userload ');
Query3.open;
If not query3. SQL. Empty then
T: = query3.fieldvalues ['maxid'];

This will not solve the essential problems ~ If no records exist in the table ~ No or wrong !?

VaR
A, B: string;
B: = formatdatetime ('yyyymmdd', date );


Query5. SQL. Add ('select max (docid) as maxid from doctor ');
Query5. SQL. Add ('where docid like: docid ');
Query5.parambyname ('docid'). asstring: = S + '% ';
Query5.open;
A: = query5.fieldbyname ('maxid'). asstring;
If a = ''then
B: = B + '1'
Else
Begin
B: = B + inttostr (strtoint (TRIM (A) + 1 );
System. Delete (B, 1, 2 );

Doctor. append;
Doctor. Fields [0]. asstring: = B;
I changed it to this now. How can I add the first and the second is wrong?

If no record exists in the table, the query result is null. You can judge this as follows,
If query3.fieldbyname ('maxid') = ''then // no records exist in the table
//
Else
//

I solved it myself ~ It is because I directly add the maximum number after extracting the current time and then cut the field, resulting in repeated primary key ~
Thank you!

Close the post ~~ Really ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.