0

这是我的代码,我试图打开与数据库的连接,然后使用 ActiveX 从表中的列中返回所有数据,然后将其输出到文本文档。我收到这个错误。

PullData.vbs(41, 1) ADODB.Recordset:在与请求的名称或序号对应的集合中找不到项目。

这是我的代码,省略了敏感信息:

Const ForReading  = 1
Dim sServer
Dim sLogin
Dim sPwd
Dim sDb

Dim oCn 
Dim oRs 
sServer   = ""
sLogin    = ""
sPwd      = ""
sDb       = ""

Set oCn = CreateObject( "ADODB.Connection" ) ' set oCn to create an object called ADODB.Connection
Set oRs = CreateObject( "ADODB.Recordset"  ) ' set oRs to create an object called ADODB.Recordset

oCn.ConnectionString = "PROVIDER=SQLOLEDB" & _      
                       ";SERVER="   & sServer   & _
                       ";UID="      & sLogin  & _
                       ";PWD="      & sPwd    & _
                       ";DATABASE=" & sDb & " "
                       oCn.ConnectionTimeout=600
                       oCn.open 'Open the connection to the server

strSelString = "select CallID from dbo.CallLog" 'this is the SQL statement that runs a query on the DB

oRs.Open strSelString,oCn 'This opens the record set and has two parameters, strSelString and oCn

If oRs.EOF Then 'If open record set is at the end of file then...
  wscript.echo "There are no records to retrieve; Check that you have the correct record number." 'echo that there is no records to retrieve.
End if

'if there are records then loop through the fields
Do While Not oRs.EOF ' Do while not open record set is not end of file

strfield = ors("Tracker")

if strfield <> "" then 'If strfield doesn't equal "" then
  Set objFileSystem    = WScript.CreateObject("Scripting.FileSystemObject") 'Set objFileSystem to create object Scripting.FileSystemObject
  Set objOutPutFile    = objFileSystem.CreateTextFile("c:\test.txt", True) 'Set objOutPutFile to create object objFileSystem.CreateTextFile  
  strcomputer = oRs 'strcomputer is set to read the line
  wscript.echo strfield  
  objOutPutFile.WriteLine  strfield &"|" 
  objFileSystem.close
  objOutPutFile.close  
end if

oRs.MoveNext
oCn.Close
Loop
4

1 回答 1

3

您要求CallID列;

"select CallID from dbo.CallLog"

但然后尝试阅读其他内容:

strfield = ors("Tracker")

所以要么选择Tracker要么阅读CallID

您也可以在循环之外创建/打开文件。

于 2013-07-11T15:32:10.037 回答