谢谢@wqw,因为您的解决方案确实有效。
这是我的第一个替代方案,它有效:
- 创建一个包含所需列的空文件/表。
- 将此文件复制到“test.dbf”。
- 将填充数据文件“链接”中的记录插入其中。
Dim dbsWork As Database
Dim qrd As DAO.QueryDef
Dim szSqlString As String
Set dbsWork = OpenDatabase(szWorkDir, False, False, "FoxPro 2.5")
Dim szFieldList As String
szFieldList = "field1, field2, field3"
szSqlString = "INSERT INTO test SELECT " & szFieldList & " FROM link"
Set qrd = dbsWork.CreateQueryDef("", szSqlString)
qrd.Execute
Set qrd = Nothing
Set dbsWork = Nothing
But the following based on @wqw's suggestion is much better, as no predefined file is required
Private Sub Test1()
Dim dbsWork As Database
Dim qrd As DAO.QueryDef
Dim szSqlString As String
Set dbsWork = OpenDatabase(MyDataBasPath, False, False, "FoxPro 2.5")
Dim szFieldList As String
szSqlString = "ALTER TABLE work.dbf ADD COLUMN fred VARCHAR(30)"
Set qrd = dbsWork.CreateQueryDef("", szSqlString)
qrd.Execute
Set qrd = Nothing
Set dbsWork = Nothing
End Sub