PDA

View Full Version : DBGrid and autoindexed fields


murphys
08-15-2001, 06:43 AM
HI

in my table, the primary key is autoindexed.
i put an editable dbgrid according to that table.
now when i add a new record, the value it gives to it is "0"
only when i close my app and re-enter it, i see the values like it should be. how come ?

10x
Amos

GeoWink
08-15-2001, 09:51 AM
Are you sure you need to use an autoindex field? I have found them to cause all kinds of trouble. I usually use an integer and a routine to find the last value and add one to it so it is unique. The field always ends up showing the proper value.

George

murphys
08-15-2001, 10:09 AM
HI
yeah but for that i will need always to check the last value in the table add 1 and use the new value.
so each time i will need to do a query just for adding a new value ?

and i want to make it as user-friendly as i can, so i made the dbgrid editable so the information can b edited by the user with no clicks and stuff.

10x
Amos

MrBaseball34
08-15-2001, 12:08 PM
Do you mean AutoIncr(ement)?

One way to handle this is to do this:

LockWindowUpdate(DBGrid1.Handle);
DBGrid1.DataSource.Dataset.Close;
DBGrid1.DataSource.Dataset.Open;
LockWindowUpdate(0);

Of course, this would move the cursor in the table but you
want to see the new value, right?