qtp执行文本中的sql语句/脚本

来源:互联网 发布:c语言中\0是什么意思 编辑:程序博客网 时间:2024/05/17 07:11

以下这段代码是让qtp执行文本中的sql语句/脚本

Set fs= createObject("Scripting.FileSystemObject")
Set sqlObj= createobject ("ADODB.connection")

Set filetext=fs.OpenTextFile("D:\testfile.txt",1,forreading)
readfile=a.ReadAll '读取文件内容
filetext.Close
Set fs=nothing
strConn="Driver={microsoft odbc for oracle}; server=**** ;uid=**;pwd=**" '此处引用oracle数据源

sqlObj.Open strConn
Set amd=createobject("adodb.command")
amd.ActiveConnection=strConn '获取command对象使用的connection对象的引用
amd.CommandText =readfile
amd.CommandType=1 'commandtype 是1为sql查询 4为存储过程
Set result=amd.Execute()
If result.State=1 Then '如果执行完毕msgbox ok
msgbox "ok"

End If

set amd=nothing
set sqlObj=nothing