| borisb 2005-10-27, 8:34 am |
| bzamfir@gmail.com wrote:
> 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
>
>
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
|