views:

444

answers:

2

I am trying to use auto incremental fields in dbx4 with a black fish database I have a simple table Structure:

    CREATE TABLE tblTABname (
    ID int AUTOINCREMENT Primary Key,
    Description varchar(100) NOT NULL );

Before Open I am doing the :

qryTAB.FieldByName( ‘ID’).AutoGenerateValue := arAutoInc;
cdsTAB.FieldByName( ‘ID’).AutoGenerateValue := arAutoInc;

After Open:

qryTab.FieldByName('ID').ProviderFlags := [pfInWhere, pfInKey];
cdsTab.FieldByName('ID').ProviderFlags := [pfInWhere, pfInKey];

If I do:

cdsTAB.Edit;
cdsTAB.FieldByName(‘Description’).value := ‘Test’;
cdsTAB.Post;

Or if I use this in a DBGRID, it fails with the error :

“Field ‘ID’ must have a value”

Witch should have been generated .

If I run an INSERT Query it works fine, with or without the “AutoGenerateValue := arAutoInc” lines.

How can I overcome this problem?

A: 

i have the same ploblem :(

how to solve?

A: 

Instead of calling CDSTab.EDIT, call CDSTab.INSERT to add a new row, only call CDSTab.EDIT when your cursor is on a record already, and to edit the value of that record.

skamradt