
Copy/Saving a recordset from one data table to another table
Many thanks to those who tried to help me with this problem. As far as I can tell from my research, the Foxpro driver or the connection I'm using does not allow the select and insert into commands. I have tried this from foxpro itself using sql and it does not work.
The solution that I adopted was to write a foxpro.dll that accepts a character string. This string contains one or more foxpro commands that are then executed. Thus, I can pass in "use employee; append from temp" and it does it and quickly too. I would have felt better if I could have done this in ADO since it would have been a more "correct" solution, but time constraints ya know...
I'll post the fox code below just in case it helps someone...
* save this code in a file vfpShell.prg (whatever) and create a project such as VFP.
* compile and build vfp.dll. Remember to include both vfp.dll and vfp.tlb in any
* installation. Otherwise it doesn't load the DLL correctly.
* To call, use for example: myo = createobject("vfp.vfpscript")
* commandStr = "use employee; copy to temp"
* myo.runscript commandStr
*
DEFINE CLASS vfpShell as CUSTOM OLEPUBLIC
PROCEDURE runScript
PARAMETERS commandStr
* setup default runtime behaviors (whatever you want)
set exclusive off
set safety off
set cpdialog off
* convert all semicolons found to carriage returns
* comandStr can be built as line1 + chr(13) + line2
* or as line1;line2 (easier)
local pos
do while .t.
pos = at(";", commandStr)
if pos = 0
exit
endif
commandstr = stuff(commandstr, pos, 1, cr)
enddo
* process commandStr breaking it into separate commands
local cr
cr = chr(13)
* trim and add cr to end if needed. Makes loop code easier to deal with
local cStr
commandStr = alltrim(commandStr)
commandStr = commandStr + iif(right(commandStr, 1) = cr, "", cr)
pos = at(cr,commandStr)
if !empty(commandStr)
do while pos <> 0
* get command
do case
case pos = 1
cStr = ""
otherwise
cStr = left(commandStr, pos - 1)
endcase
* remove command from master string
commandStr = iif(pos = len(commandStr),"",substr(commandStr, pos + 1))
if !empty(cStr) then
&cStr
endif
pos = at(cr, commandStr)
enddo
endif
ENDPROC
ENDDEFINE
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!