|
写了这样两个函数Function OpenConnection()
Dim conn,res '定义变量
set conn = CreateObject("ADODB.Connection") '创建连接
conn.ConnectionString="rovider=SQLOLEDB.1assword=123456ersist Security Info=True;User ID=sa;Initial Catalog=fc_hangzhou;Data source=192.168.2.234" '设置连接字符串
conn.open '开启连接
Set res = CreateObject("ADODB.RecordSet")
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
QTP报错,说是 res.open sql,conn,1,1类型或参数不匹配
谁能告诉我怎么改才正确,谢谢了 |
|