哇......我認爲你正在錯誤地做這件事......只需對SQL數據庫執行一個簡單的SQLCONNECT(),對數據源,存儲過程或其他任何方式運行查詢,並將其放入遊標中在VFP ......然後,你可以「複製」到DBF和你做...像
lnH = SQLCONNECT()
(彈出對話框你ODBC連接)。
如果不是,你可以做
lnH = SQLStringConnect("Provider=... for sql server, server name, etc")
然後
if lnH > 0
sqlexec(lnH, "select * from someTableOnServer where whateverConditon", "C_LocalCursor")
select C_LocalCursor
copy to PermanentTable
sqldisconnect(lnH)
endif
現在,如果有長度超過10個字符的列名,並且不使用數據庫容器列,您可能需要通過更改查詢來獲取列名稱,或者重新選擇本地數據以適應10個字符的非dbc表格上下文進行調整。
又如打造出來的查詢可以是 - 對於可讀性的簡單打字時,我用文字/ ENDTEXT如
text to lcSQLCmd noshow pretext 1+2
select
t1.Column1,
t1.AVeryLongColumnName as AVLColName,
t1.AnotherLongColumn2 as ALC2,
t1.SomeFlag,
t2.ColumnFromAnotherTable as CFATbl,
t2.AnotherCol
from
SQLDatabase.dbo.SQLTable1 t1
join SQLDatabase.dbo.SQLTable2 t2
on t1.SomeKey = t2.SomeKey
where
t1.SomeCriteria = 'whatever'
order by
t1.SomeFlag
endtext
*/ Then, to "clean up" the string for VFP to pass properly,
*/ strip out the cr/lf from the text such as
lcSQLCmd = chrtran(lcSQLCmd, chr(13)+chr(10), "")
*/ THEN, pass this command through sqlexec()
sqlexec(lnH, lcSQLCmd, "C_LocalCursor")
第二顯然是更容易閱讀你正在試圖讓,並注意我還將長列名稱預縮短爲VFP 10 char非DBC列名稱限制。然後,就像第一個例子一樣複製出來。
我非常感謝您的洞察力和詳細的迴應。我很少在FoxPro工作,並沒有考慮這種方法。 (有時候,當人們用另一種方法非常接近有效的解決方案時,甚至不會考慮改變策略。)這很好,我也學到了一些東西。謝謝。 – RIDER