Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update SQL
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00811836
Message ID:
00811877
Vues:
23
>Gaylen,
>
>You have to pull the value to a memvar before you use it in a SQL command. This is because the SQL actually executes outside the form method.

Hi David,

Your's workaround is correct but you're mistaken about the cause of the problem. The SQL command excuted in a method of the form/class runs in the context of this method and can access properties of the form/class. It's a bug in UPDATE command that property referenced in SET on the right side of "=" sign generates an error. Run following code and click on Command1 button to see that the first two SQL commands have no problem referencing form properties.
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	Top = 0
	Left = 0
	Height = 200
	Width = 347
	DoCreate = .T.
	Caption = "Form1"
	AlwaysOnBottom = .T.
	Name = "Form1"
	oprevcontrol = .F.
	lreadonly = .F.
	lreturnval = .F.
	DIMENSION alist[1]
	ADD OBJECT text1 AS textbox WITH ;
		Height = 23, ;
		Left = 84, ;
		Top = 12, ;
		Width = 100, ;
		Name = "Text1"
	ADD OBJECT text2 AS textbox WITH ;
		Height = 23, ;
		Left = 84, ;
		Top = 48, ;
		Width = 100, ;
		Name = "Text2"
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 120, ;
		Left = 96, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"
	PROCEDURE command1.Click
		OPEN DATABASE (HOME(2) + "\data\testdata")
		oForm.text1.Value = "     1"
		* No error in select
		SELECT * FROM products ;
			WHERE product_id = oForm.text1.Value ;
		INTO CURSOR crsProd
		oForm.text2.Value = crsProd.eng_name
		* No error in UPDATE
		UPDATE products SET eng_name = eng_name ;
			WHERE product_id = oForm.text1.Value
		* Error in UPDATE
		UPDATE products SET eng_name = oForm.text2.Value ;
			WHERE product_id = oForm.text1.Value
	ENDPROC
ENDDEFINE
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform