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 に答える