qtp读取sql脚本内容执行sql

2011-08-09  刘可君 

好久时间没有写东西了,今天写点吧~
以下这段代码是让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
300°/2967 人阅读/4 条评论 发表评论

邓智群  2011-08-09

找了好久没有找到,终于找到了,谢谢你


熊志男  2011-08-09

邓智群: 找了好久没有找到,终于找到了,谢谢你
便宜你了


小窝  2011-08-17

已同步至官方微博


马梦福  2011-08-17

knkn


登录 后发表评论