我只是想将查询结果写入 .txt 文件。我被赶上了,似乎无法进一步进步。
' # writes records to a .txt file
Wscript.timeout = 600
Const adLockBatchOptimistic = 4
Const adUseClient = 3
Const writeFile = "C:\Path\CallLog.txt"
Dim strWrite, strSQL, strResult
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionTimeout=30
conn.CommandTimeout=30
conn.Open "Provider=SQLOLEDB;Data Source=Server;Trusted_Connection=Yes;" & _
"Initial Catalog=Database;User ID=User;Password=Password;"
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT fld1, fld2, " & _
"fld3, fld4, fld5, fld6, fld7, fld8, fld9" & _
"FROM Database.dbo.[table]"
'conn.Execute strSQL
rs = strSQL, conn ' <- this line causes an error.
Open writeFile For Ouput As #1
Do Until rs.EOF
strResult = rs
Print #1, strResult
rs.MoveNext
Loop
Close #1
rs.Close
Set rs = Nothing