【seagull1985-QTP】oracle数据库查询
'==========================================================================' NAME: Database processing
' AUTHOR: heyl
' DATE: 2013-07-12
' COMMENT:
'==========================================================================
Class Db_procs
'PopBox Processing
sub PopBox(Prompt,intSecond,strTitle)
dim obj
set obj = createobject("WScript.Shell")
obj.Popup Prompt,intSecond,strTitle
set obj=nothing
end sub
'Create database link
Function CreOraLink(provider,userid,passwd,dataip,strsql,columnname)
Dim Cnn,strCnn
strCnn ="Provider="&provider&";Password="&passwd&";Persist Security Info=True;User ID="&userid&";Data Source="&dataip
Set Cnn = CreateObject("adodb.Connection")
Cnn.Open strCnn
If Cnn.State = 0 Then
Call PopBox("创建数据库链接失败",30,"数据库链接")
End If
'Generate the recordset object
Set Rs = CreateObject("ADODB.Recordset")
'excute sql
Rs.Open strsql,Cnn,1,3
'if you want judge the database state,must define(DS_dbrc) a global variable in QTP
DS_dbrc = Rs.Recordcount
if DS_dbrc <> 0 Then
DS_dbvalue = Rs(columnname)
if DS_dbvalue <> "" Then
DS_dbvalue = Cstr(DS_dbvalue)
End if
else
DS_dbvalue = ""
End if
Rs.close
Set RS=nothing
Cnn.Close
Set Cnn=nothing
End Function
End Class
' Dim DS_dbvalue
' Set DBP = new Db_procs
' ttt = "select * from HPSTJNL_CHECKED"
' Call DBP.CreOraLink("MSDASQL.1","mast","mast","10.211.16.120",ttt,0)
' msgbox DS_dbvalue
' ttt = "select * from HPSTJNL"
' Call DBP.CreOraLink("MSDASQL.1","mast","mast","10.211.16.120",ttt,"txn_cd")
' msgbox DS_dbvalue
学习中,谢谢 棒棒哒
页:
[1]