Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Mike Yearwood
  Where is Mike Yearwood?
 Toronto
 Canada
 Mike Yearwood
 To: dragon 5
  Where is dragon 5?
 Johor
 Malaysia
 dragon 5
 Tags
Subject: RE: use GETAUTOINCVALUE() is suitable?
Thread ID: 287888 Message ID: 289417 # Views: 28 # Ratings: 0
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Friday, December 31, 2010 7:56:04 PM         
   


> >
> >
> > You are using that for usage as Foreign Key on another table right? If so, then you don't need to base it on GETAUTOINCVALUE(). Get the Integer AI on the recently saved record of the parent table because that is where you will be linking the child records anyway:
> >
> >
> > SET AUTOINCERROR OFF 
> > CREATE CURSOR parentdbf (parentPK I AUTOINC, xName c(40))
> > CREATE CURSOR childdbf (childPK I AUTOINC, ParentFK I, Age N(2,0))
> > 
> > * Create records for parent
> > INSERT INTO parentdbf VALUES (0,"JUN")
> > SELECT parentdbf
> > BROWSE NORMAL 
> > 
> > * create corresponding record to child
> > * use the parent's integer autoinc field's (PARENTPK) currently saved record's value
> > INSERT INTO childdbf VALUES (0, parentdbf.parentpk,39)  
> > 
> > SELECT childdbf 
> > BROWSE NORMAL 
> > 
> > * Join Data to get the full picture
> > SELECT xName, Age FROM parentdbf LEFT OUTER JOIN childdbf ON parentdbf.parentpk = childdbf.parentfk

> >
> > http://www.junblogs.com/
> > http://weblogs.foxite.com/sandstorm36/default.aspx
> > http://www.coderisland.com/forum/viewforum.php?f=10
>
>
> Dear mr. Jun,
>
> But in the multiuser environment, will it get the correct autoInc value?
> I was worry that will get the wrong autoInc Id.
>
> Thanks.
> dragon 5
After the insert into the parent table, the record pointer moves to that record. It has the new autoinc value. Users will not interfere with each other.

Mike Yearwood
Microsoft MVP Visual FoxPro 2008, 2009
We have enough youth. We need a fountain of smart!
There may be many ways to skin a cat, but there are very few right ways to do it.

ENTIRE THREAD

use GETAUTOINCVALUE() is suitable? Posted by dragon 5 @ 12/15/2010 3:51:57 PM
RE: use GETAUTOINCVALUE() is suitable? Posted by Ony Too @ 12/15/2010 11:37:56 PM
RE: use GETAUTOINCVALUE() is suitable? Posted by Jun Tangunan @ 12/16/2010 1:22:38 AM
RE: use GETAUTOINCVALUE() is suitable? Posted by dragon 5 @ 12/31/2010 11:49:45 AM
RE: use GETAUTOINCVALUE() is suitable? Posted by Mike Yearwood @ 12/31/2010 7:56:04 PM