>>TEXT TO sqlcommand TEXTMERGE NOSHOW
>> INSERT INTO Table1 VALUES('first','second')
>>ENDTEXT
>>
> Vladimer,
>
>This works! However when I chnge the above line to
>
>INSERT INTO Table1 FROM MEMVAR
>
>I get an ODBC connectivity error. I vaguely recall that there is something special that needs to be done with the TEXT TO command to perform something like macro substitution.
>Any hints?
The memvar thing won't work, because you aren't sending them to the ODBC driver - you're sending text. Therefore, you need to give it text. There are several ways to convert your variables into text. One is to use VFP's automatic conversion:
TEXT TO sqlcommand TEXTMERGE NOSHOW
INSERT INTO Table1 VALUES(?mvar1,?mvar2)
ENDTEXT
Note that the variables need to be in scope when SqlExec() call is executed.
Another way is to roll your own conversion, i.e. have a function which would return a proper string representation of anything:
TEXT TO sqlcommand TEXTMERGE NOSHOW
INSERT INTO Table1 VALUES(<<toString(mytable.field1)>>,<<toString(mytable.field2)>>)
ENDTEXT
Formatting may be quite straightforward - you need quotation marks around the strings, numbers as they come out of str() function, but you may need to find out the proper format for logicals, dates, datetimes and memos. Memos may go as strings, but if they contain carriage returns and/or other nonprintables, this may be a problem.