If conn.state=0 Then '如果连接状态为0,表示连接失败,写入reporter对象中,否则表示连接成功
Reporter.ReportEvent micFail,"testing","数据库连接失败"
res.close '关闭结果集和连接,并且置为空
Set res = nothing
conn.close
Set conn = nothing
else
reporter.ReportEvent micPass,"数据库链接","数据库连接成功"
End If
End Function
Function GetOne(sql)
Dim conn,res '定义变量
conn=OpenConnection()
Set res = createObject("ADODB.RecordSet")
res.open sql,conn,1,1
GetOne = null
'如果结果集有记录,且不是指向结果集最后,res.eof = false
If not res.eof Then
GetOne = res.Fields(0).value
End If
End If
Set res = nothing
End Function
然后我调用函数来查找信息,脚本为
Dim a
a=GetOne("select leasecount from fc_main.dbo.custbaseinfo wehre custname='杰特'")
msgbox a