Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Of @@identity and surrogate keys - HELP!
Message
De
09/12/1999 21:45:06
 
 
À
09/12/1999 16:50:36
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00301334
Message ID:
00301485
Vues:
35
>If I now (after the initial tableupdate to do the insert) change a field and try to update again, it fails because the code generated by TableUpdate() still looks for "where keyfield = 0" I can see this in SQL Profiler. Now - even IF I REPLACE the keyfield in the cursor with the correct identity#, tableupdate STILL uses "where keyfield = 0" in its update statement!! Refresh() doesn't have any effect either.
>

OK... I ran through this scenerio... and, you can put this in your book of Stupid FoxPro Tricks (others call it a bug)... For some reason, the non-updatable field is retaining a field state of 2 after you do the replace. Changing the record pointer seems to eleviate this problem... so, if after you did your replace MyView_PK with SQLRESULT.EXP you moved to another record, and then back, make a change, your tableupdate would work... at least my testing showed this.

Here is the 'trick'... after you do the replace issue this line of code...

goto recno()

HA!... don't laugh... it worked for me. Here is the code I tested with... I added an Identity field to the Authors Table of the PUBS sample data...
select PUBS_AUTHORS

Append Blank
Replace ;
	Au_ID with '999-99-'+left(tran(seconds()),4),;
	Au_Lname with 'LastName',;
	Au_FName with 'FirstName',;
	Phone with '999 555-7878',;
	Address with '1 First Street',;
	City with 'Tampa',;
	State with 'FL',;
	ZIP with '33624',;
	Contract with .t.
	
If TableUpdate()
	Wait Window 'Record Added'
else
	local aErrors[1]
	aError( aErrors )
	wait window aErrors[2]
	return
endif

Local nConn

nConn = CursorGetProp("ConnectHandle")

If SQLExec( nConn, "Select @@Identity") = 1
	wait window 'Got Identity Value'
	local iIdentity
	iIdentity = SQLRESULT.EXP
	use in SQLRESULT
else
	Wait Window 'Unable to get Identity'
	return
EndIf

select PUBS_AUTHORS
replace Author_PK with iIdentity
? getfldstate(-1)
goto recno()
? getfldstate(-1)

replace Address with 'New Address for this record.'

If TableUpdate()
	wait window 'Updated Change of new record!'
Else
	local aErrors[1]
	aError( aErrors )
	wait window aErrors[2]
EndIf
>Any help is GREATLY appreciated.

HTH,

BOb
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform