本帖最后由 测试积点老人 于 2018-12-26 16:01 编辑
连接数据库代码:- 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- <p style="line-height: 28px;">Set Conn=CreateObject("ADODB.Connection")</p><p style="line-height: 28px;">str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.1.100;DATABASE=wp_blog;user id=zzz;password=123456"</p><p style="line-height: 28px;">Conn.open str</p><p style="line-height: 28px;">Set Rs=CreateObject("ADODB.Recordset")</p><p style="line-height: 28px;">sql="select*from`wp_blog`.`blg_webcategory`limit 0,5000;" '(分页查询)</p><p style="line-height: 28px;">Rs.open sql,conn,1,3</p><p style="line-height: 28px;">If(not Rs.eof)then</p><p style="line-height: 28px;">Rs.MoveFirst</p><p style="line-height: 28px;">MsgBox Rs(0)</p><p style="line-height: 28px;">MsgBox Rs(1)</p><p style="line-height: 28px;">MsgBox Rs(2)</p><p style="line-height: 28px;">MsgBox Rs(3)</p><p style="line-height: 28px;">end if</p><p style="line-height: 28px;">Rs.Close</p><p style="line-height: 28px;">Set Rs=Nothing</p><p style="line-height: 28px;">Conn.Close</p><p style="line-height: 28px;">Set Conn=Nothing</p>
复制代码
用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- <p style="line-height: 28px;">Set Conn=CreateObject("ADODB.Connection")</p><p style="line-height: 28px;">str="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/db1.mdb"</p><p style="line-height: 28px;">Conn.open str</p><p style="line-height: 28px;">Set Rs=CreateObject("ADODB.Recordset")</p><p style="line-height: 28px;">56.*.xml</p><p style="line-height: 28px;">Environment.LoadFromFile"D:\新建文件夹\a.xml"</p><p style="line-height: 28px;">Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("wd").Set Environment("HuiYuanB")</p>
复制代码
|