UFT操做SQLServer,MySQL,Oracle,DB2,Access數據庫的方法

鏈接數據庫代碼:

Set Conn = CreateObject("ADODB.Connection" )
	str="DRIVER=SQL Server;SERVER=192.168.1.109;UID=wangshaoping;PWD=wsp;APP=Microsoft Office 2003;WSID=wangshaoping;DATABASE=test_data" 
	Conn.open str
	
	Set Rs = CreateObject ("ADODB.Recordset" )
'	Set comm= createobject("ADODB.Command")
	sql ="select * from abnormity_data where name_yc = 'yejian(00003)'"
	Rs.open sql,conn,1,3
	i = rs.RecordCount
'
'        comm.CommandText = sql
'        comm.ActiveConnection = Conn
'        Set Rs = comm.Execute
'		
	msgbox rs.Fields.Count 
 
	arrTemp = Rs.GetRows()
	
	for j=0 to i-1 
	msgbox arrTemp(0,j)&arrTemp(1,j)&arrTemp(2,j)&arrTemp(3,j)
	next
	Rs.Close
    Set Rs = Nothing
	
	Conn.Close
	Set Conn = Nothing

1、SQL Server

(本地無需安裝SQL Server)mysql

connectionstring(鏈接字符串):web

1.本地沒有建立數據源的方式sql

DRIVER=SQL Server;SERVER=數據庫IP地址;UID=用戶名;PWD=密碼;APP=Microsoft Office 2003;WSID=本地主機名;DATABASE=數據庫名數據庫

實例:oracle

DRIVER=SQL Server;SERVER=10.160.11.10;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJHLJUN;DATABASE=dcworkide

2.本地已建立數據源的方式ui

DSN=數據源名稱;UID=用戶名;PWD=密碼;APP=Microsoft Office 2003;WSID=數據庫的主機名;DATABASE=數據庫名spa

實例:code

DSN=LocalServer;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJDCWORKTEST;DATABASE=dcworkorm

3.SQL語句實例(從數據庫表HR_LANGUAGE_TYPE中,查詢字段語言名稱LANGUAGE_NAME,條件語言名稱=中文,按語言名稱升序排序結果)

source(SQL語句):

SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM dcwork.dbo.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE(HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME

2、DB2格式

(本地至少安裝DB2 Run-Time Client Lite)

connectionstring(鏈接字符串):

1.本地沒有建立數據源的方式

DRIVER={IBM DB2 ODBC DRIVER};UID=用戶名;PWD=密碼;MODE=SHARE;DBALIAS=數據庫名;

實例:

DRIVER={IBM DB2 ODBC DRIVER};UID=db2admin;PWD=db2admin;MODE=SHARE;DBALIAS=DCWORK;

2.本地已建立數據源的方式

DSN=數據源名稱;UID=用戶名;PWD=密碼;MODE=SHARE;DBALIAS=DCWORK;

實例:

DSN=DWCORKDB2;UID=db2admin;PWD=db2admin;MODE=SHARE;DBALIAS=DCWORK;

3.SQL語句實例

source:SQL語句

SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM DB2ADMIN.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE(HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME

3、Oracle格式

(本地須要安裝Oracle ODBC DRIVER)

connectionstring(鏈接字符串):

1.本地沒有建立數據源的方式

DRIVER={Oracle in OraHome92};SERVER=數據庫服務名;UID=用戶名;PWD=密碼;DBQ=數據庫名;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BAM=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F;PFC=10;TLO=O;

實例:

DRIVER={Oracle in OraHome92};SERVER=DCWORK;UID=DCWORK;PWD=DCWORK;DBQ=DCWORK;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BAM=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F;PFC=10;TLO=O;

2.本地已建立數據源的方式

DSN=數據源名稱;UID=用戶名;PWD=密碼;DBQ=數據庫名;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;

實例:

DSN=dcworkoracle;UID=DCWORK;DBQ=DCWORK;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;

3.SQL語句實例

source:SQL語句

SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM DCWORK.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE(HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME

四,mysql

Set Conn=CreateObject("ADODB.Connection")

str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.1.100;DATABASE=wp_blog;user id=zzz;password=123456"

Conn.open str

Set Rs=CreateObject("ADODB.Recordset")

sql="select*from`wp_blog`.`blg_webcategory`limit 0,5000;" '(分頁查詢)

Rs.open sql,conn,1,3

If(not Rs.eof)then

Rs.MoveFirst

MsgBox Rs(0)

MsgBox Rs(1)

MsgBox Rs(2)

MsgBox Rs(3)

end if

Rs.Close

Set Rs=Nothing

Conn.Close

Set Conn=Nothing

用vbs取Mysql中文出現亂碼

sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=code52_lib; UID=root;PASSWORD=123456; OPTION=3;Stmt=Set Names 'GBK'"   

五,Access

Set Conn=CreateObject("ADODB.Connection")

str="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/db1.mdb"

Conn.open str

Set Rs=CreateObject("ADODB.Recordset")

56.*.xml

Environment.LoadFromFile"D:\新建文件夾\a.xml"

Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("wd").Set Environment("HuiYuanB")

相關文章
相關標籤/搜索