gpt4 book ai didi

sql - 查询SQL数据库时出现EOF和BOF错误

转载 作者:行者123 更新时间:2023-12-04 15:02:21 25 4
gpt4 key购买 nike

我正在尝试从 vbs 查询 SQL 数据库,但是当没有找到记录时,我收到一个错误

ADODB.Field : Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.



我想我需要使用 IF NOT 语句来捕获是否找不到记录,但我无法弄清楚它需要去哪里。
Do Until objFile.AtEndofStream
strAppName = objFile.ReadLine

ConnString="DRIVER={SQL Server};SERVER=aardvark002;UID=***;PWD=***;DATABASE=DEW_Users"
SQL = "USE Win7AppData SELECT " & Chr(34) & strCountry & Chr(34) & " FROM AppsByCountry WHERE Application = '" & strAppName & "'"

Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
Connection.Open ConnString
Recordset.Open SQL,Connection
strApproval = Recordset(strCountry)
If StrApproval = "YES" Then
strApproval = "Approved"
Else
strApproval = "Denied"
End If
objExcel.Cells(intRow, 1).Value = strAppname
objExcel.Cells(intRow, 2).Value = strCountry
objExcel.Cells(intRow, 3).Value = strApproval
intRow = intRow + 1
Loop

最佳答案

我的 VBScript 有点生疏,但你应该能够在 Recordset 上使用 .EOF 来检查它是否在最后:

Recordset.Open SQL,Connection
If Recordset.EOF = false Then
' have some rows, do what you want with them
End If

W3Schools reference

关于sql - 查询SQL数据库时出现EOF和BOF错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10225551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com