连接字符串
'========================================
'名称: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=strCnnEnd Function1 sqlserver 数据库
Dim ConnectionString,SqlConnection,SqlCommand,SqlDataAdapter,DataSet
ConnectionString=get_ConnectorStr("2")Set SqlConnection=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlConnection","System.Data",ConnectionString)SqlConnection.OpenSet 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 DataSetSqlConnection.CloseMsgBox DataSet.Tables.get_Item(0).Rows.Count