QTP自动化测试-连接数据库
作者:互联网
连接字符串
'========================================
'名称:get_ConnectorStr
'作用:获取连接字符串
'参数:1 =mysql ; 2=sqlserver; 3 oracle
'返回值:连接字符串
'调用:msgbox get_ConnectorStr("数据库类型")
'========================================
Function get_ConnectorStr(strtype)
Dim strCnn
If strtype=1 Then
'mysql
strCnn="DSN=testmysqlforqtp;DATABASE=testwin;PWD=123;PORT=3306;SERVER=192.168.1.75;UID=root"
ElseIf strType=2 Then
strCnn="Data Source=.;Initial Catalog=testdata66;Persist Security Info=True;User ID=sa;PassWord=123"
End If
get_ConnectorStr=strCnn
End Function
1 sqlserver 数据库
Dim ConnectionString,SqlConnection,SqlCommand,SqlDataAdapter,DataSet
ConnectionString=get_ConnectorStr("2")
Set SqlConnection=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlConnection","System.Data",ConnectionString)
SqlConnection.Open
Set SqlCommand=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlCommand","System.Data","select * from tbinfopart",SqlConnection)
Set SqlDataAdapter=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlDataAdapter","System.Data",SqlCommand)
Set DataSet=DotNetFactory.CreateInstance("System.Data.DataSet","System.Data")
SqlDataAdapter.Fill DataSet
SqlConnection.Close
MsgBox DataSet.Tables.get_Item(0).Rows.Count
标签:QTP,get,数据库,CreateInstance,System,自动化,SqlConnection,Data,ConnectorStr 来源: https://www.cnblogs.com/caojuansh/p/10938245.html