|
Home > Archive > FoxPro Help and Support > October 2005 > Using table with CursorAdapter - how can I get the ID of latest record?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using table with CursorAdapter - how can I get the ID of latest record?
|
|
| bzamfir@gmail.com 2005-10-27, 8:34 am |
| Hi,
I have an application and I use CursorAdapters for all tables.
I have the following problem: I have to create a new record in a table,
find it't id (integer auto-increment) and pass it to another module
Specifically, user create a master record, then (before they save and
exit) they can also create one or more child records in several other
tables. So when they open the forms for the child tables, I havre to
know the ID for the master record, and pass it to the form handling the
child table, to set it as foreign key.
The problem is I have troubles finding the ID. I use a very odd method
right now, which works, but I'm not happy with it.
Can anyone give me so thoughts on how to get this done in an elegant
way?
Thanks,
Bogdan
| |
|
|
"borisb" <borisb@mail.bg> wrote in message news:ugCsry#zFHA.720@TK2MSFTNGP15.phx.gbl...
> bzamfir@gmail.com wrote:
>
> Something like that:
> Field1 is AutoIncrement field and you put it into the selectcmd property
> of the CA.
>
> INSERT INTO MyCA (Field2, Field3...FieldN) VALUES (val1,val2...valN)
> IF TableUpdate(1, .t., "MyCA")
> MyCursorAdapterObjec
t.CursorRefresh()
> *** Find the record you just added (use see, locate, goto etc.)
> m.lnNewId = Field1
> ENDIF
>
In VFP9, you can get ID value automatically using CA properties
InsertCmdRefreshFiel
dList (= your_ID_field_name) and InsertCmdRefreshCmd
(I'd like here to be just "SELECT TOP 1 GETAUTOINCVALUE()", but there is a problem with
required FROM clause in Fox's SQL dialect, so I use a dummy one-record table t_ainc
and "SELECT GETAUTOINCVALUE() AS new_id FROM t_ainc".
Anyway, it works - after TABLEUPDATE() I have my ID's updated!)
| |
| bzamfir@gmail.com 2005-10-27, 8:34 am |
| Thanks, I'll try it and see how it works.
Regards,
Bogdan
|
|
|
|
|