编写一个查询输出使用FileSystemObject的文本文件文本文件、FileSystemObject

2023-09-08 11:34:54 作者:情之所钟,岂在容颜

有没有办法编写一个查询输出,使用FileSystemObject的一个文本文件?

Is there a way to write a query output to a text file using FileSystemObject?

推荐答案

什么是查询结果的格式?你也许可以做这样的事情,如果它是一个简单的字符串,或者您可能需要提取你需要的比特。

What's the format of the query results? you may be able to do something like this if it's a simple string, or you may have to extract the bits that you need.

这里的code使用FileSystemObject写一个字符串到一个文本文件中:

Here's the code to write a string to a text file using the filesystemobject:

Const fsoForAppend = 8

Dim objFSO
Dim queryResult

queryResult = 'OMG no results'

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\path\to\logfile.txt", fsoForAppend)

'Write the results to the textfile
objTextStream.WriteLine queryResult

'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing