连接数据库代码:
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
一、sql Server
(本地无需安装sql Server)
connectionstring(连接字符串):
1.本地没有创建数据源的方式
DRIVER=sql Server;SERVER=数据库IP地址;UID=用户名;PWD=密码;APP=Microsoft Office 2003;WSID=本地主机名;DATABASE=数据库名
实例:
DRIVER=sql Server;SERVER=10.160.11.10;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJHLJUN;DATABASE=dcwork
2.本地已创建数据源的方式
DSN=数据源名称;UID=用户名;PWD=密码;APP=Microsoft Office 2003;WSID=数据库的主机名;DATABASE=数据库名
实例:
DSN=LocalServer;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJDCWORKTEST;DATABASE=dcwork
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
二、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
三、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,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
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")