Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with AutoIncrement..

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA

I am using Delphi 6 and Interbase 6 and have the following
in the script of a DataBase

create trigger CID_NOinsert for CHILD
before insert
position 0
as
begin
NEW.CID_NO = gen_id(cld_number_gen,1);
end!!

Upon scrolling onto a new record in a grid (and despite the above) no value is evident in CID_NO.

However if I enter a number (anything!) into CID_NO AND move off the record (thus Posting) the number which I have entered is corrected to what it should be according to the above trigger. And becomes visible upon scrolling back to the record.

The frustrating thing is the absolute need to have to enter a No into CID_NO manually.

Can anyone please suggest how to get around this?

Thanks in advance.

Terry
 
Make the CID_No field read-only so the the program will not look for user input. Instead of dbEdit use dbTextif you are not using a dbGrid.

Regards Steven van Els
SAvanEls@cq-link.sr
 
Another option is using a stored procedure. For example

Code:
CREATE PROCEDURE GET_CID_NO
RETURNS (
    CID_NO INTEGER)
AS
begin
 CID_NO = gen_id(cld_number_gen, 1);
end
Then in your program you add IBStoredProc and bind it to your stored procedure on server. And write AftefInsert handler for your dataset like this:
Code:
begin
  spGetCIDNO.ExecProc;
  MyDataSet.FieldByName('CID_NO').asInteger := spGetCIDNO.ParamByName('CID_NO').asInteger;
end

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top