我正在使用VB尝试访问MSACCESS中的数据库。
我正在做这个非常愚蠢的事情:SSQL9 = "select Username as docuser from Doctors where TreatmentField = '"&Treatment&"'"
set Rs9 = Server.CreateObject("ADODB.recordset")
Rs9.open SSQL9,conn
Something=Rs9("docuser")
Response.Write(Something)
出于某种原因,我得到了:
ADODB.Field错误'800a0bcd'
BOF或EOF为True,或者当前记录已被删除。请求的操作需要当前记录。
虽然我确定但有记录。导致错误的原因是什么?
答案 0 :(得分:1)
@eve:对我来说,看起来更像VBScript而不是VB ...假设conn
是ADODB.Connection
对象,除非你',否则你不需要创建RecordSet
对象将继续使用分页,因此您可以将代码示例重写为 -
If Treatment <> "" Then
SSQL9 = "SELECT Username as docuser FROM Doctors WHERE (TreatmentField = '" & Treatment & "')"
Set Rs9 = con.Execute(SSQL9)
If NOT Rs9.EOF Then
Something = Rs9(0)
Response.Write(Something)
Else
' Empty recordset '
End If
Rs9.Close
Else
Response.Write "No 'Treatment' input was sent"
End If
答案 1 :(得分:0)
对于类似的任务,我们使用这样的代码:
Dim QD As adodb.Command
Dim rs As adodb.Recordset
Set QD = New adodb.Command
QD.CommandText = sql
QD.CommandType = adCmdText
QD.ActiveConnection = conn
Set rs = QD.Execute
要追踪错误,请按以下步骤操作:
要获取所有记录,您需要某种循环
Do While Not rs9.EOF
Something=Rs9!docuser
Response.Write(Something)
RS9.MoveNext
Loop
更改了代码:
现在使用Something = Rs9!docuser请尝试