Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update SQL
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00811836
Message ID:
00811877
Views:
22
>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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform