QTP链接Oracle,Access,SqlServer3种常用数据库

上一篇 / 下一篇  2015-06-19 10:20:41 / 个人分类:数据库

'链接Sql server数据库
Dim AdoCnn ,strDb,Rst,strCnn,ilen ,strsql '//定义变量
strCnn=" DSN=sa;Description=study_Qtp;UID=sa;PWD=888888;APP=UFTBase;WSID=WIN-TU8U121LBFN;DATABASE=study_Qtp"
Set AdoCnn=CreateObject("ADODB.Connection") '//生成数据库连接对象
AdoCnn.Open strCnn   '   //打开数据库
If AdoCnn.State=0 Then '判断是否链接数据库成功
msgbox "Connect Fail"
else
msgbox "Connect Success"
End If

strsql="select x  FROM Study_Qtp1"
Set Rst =AdoCnn.Execute(strsql)
'方法一 得到所有列值
While not Rst.EOF
msgbox Rst.Fields.Item("x").Value
Rst.MoveNext

Wend

'方法二得到所有列值

Rst.Close
AdoCnn.close
Set AdoCnn=Nothing
Set Rst=Nothing





'链接ACcessS数据库

Dim AdoCnn ,strDb,Rst,strCnn,ilen ,strsql '//定义变量
strCnn=" DSN=db_access;DBQ=E:\study\qtp12\test_access.accdb;DefaultDir=E:\study\qtp12;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5"
Set AdoCnn=CreateObject("ADODB.Connection") '//生成数据库连接对象
AdoCnn.Open strCnn   '   //打开数据库
If AdoCnn.State=0 Then '判断是否链接数据库成功
msgbox "Connect Fail"
else
msgbox "Connect Success"
End If

strsql="select x from calc"
Set Rst =AdoCnn.Execute(strsql)
'方法一 得到所有列值
While not Rst.EOF
msgbox Rst.Fields.Item("x").Value
Rst.MoveNext
Wend
Rst.Close
AdoCnn.close
Set AdoCnn=Nothing
Set Rst=Nothing


'链接Oracle数据库
Dim AdoCnn ,strDb,Rst,strCnn,ilen ,strsql '//定义变量
strCnn=" DSN=db_oracle;UID=studyoracle_user;PWD=studyoracle_user"
Set AdoCnn=CreateObject("ADODB.Connection"'//生成数据库连接对象
AdoCnn.Open strCnn   '   //打开数据库
If AdoCnn.State=0 Then '判断是否链接数据库成功
msgbox "Connect Fail"
    else
    msgbox "Connect Success"
End If

strsql="select name from study_test1"
Set Rst =AdoCnn.Execute(strsql)
'方法一 得到所有列值
While not Rst.EOF
    msgbox Rst.Fields.Item("name").Value
    Rst.MoveNext

Wend
Rst.Close
AdoCnn.close
Set AdoCnn=Nothing
Set Rst=Nothing


TAG: Oracle 常用数据库

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-06  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 2442
  • 日志数: 4
  • 文件数: 1
  • 建立时间: 2013-11-07
  • 更新时间: 2015-06-19

RSS订阅

Open Toolbar