whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

26 Visitors Online


 
...create an AutoIncrement using SQL?
Autor: Ido Kanner
[ Print tip ]  

Tip Rating (3):  
     


{
  Lets say that we wish to create a fallawing number (Autoincrese) of an item,
  without using the AutoIncrese filed.
  This is usfull when for example there is more users from the same IP that log
  in or any other things that you wish.

  This example will show you how to do it with some checking of filled data,
  but it can be done anyway you wish.

  You need a Table with at least 2 fileds with number casting, and a TQUERY component.
}


function TForm1.GetNextNumber : integer;
begin
 
qryMain.Active := False;
 qryMain.SQL.Clear;
 qryMain.SQL.Add('Select Max(FieldToIncrease) from tblMain where (Cheking >=1);');
 qryMain.Active := True; //We executed the query

 
if qryMain.RecordCount >= 0 then
  
result := qryMain.FieldByName('FieldToIncrese').AsInteger +1;
 else result := 1;
end;

...

procedure TForm1.SetNextNumber;
begin
 
//You must first see if the table is in insert/update mode before using this procedure.
 
tblMain.FieldByName('FieldToIncrese').AsInteger := GetNextNumber;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners