一、连接:Mssql 实例
Dim rs,cmd,sql
Set rs=createobject("adodb.recordset")
Set cmd=createobject("adodb.command")
cmd.activeconnection="Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=fd_xzfw;Data source=192.168.0.111"
cmd.commandtype=1
sql="select * from zfoa_user where user_code='admin'"
cmd.commandtext=sql
Set rs =cmd.execute()
Set rs=nothing
Set cmd.activeconnection=nothing
Set cmd=nothing
Set rs=createobject("adodb.recordset")
Set cmd=createobject("adodb.command")
cmd.activeconnection="Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=fd_xzfw;Data source=192.168.0.111"
cmd.commandtype=1
sql="select * from zfoa_user
cmd.commandtext=sql
Set rs =cmd.execute()
Set rs=nothing
Set cmd.activeconnection=nothing
Set cmd=nothing
二、连接:Access 实例
Option explicit
Dim Cnn ,strDb,Rst,strCnn,ilen '//定义变量
strCnn="Provider=Microsoft.Jet.OLEDB.4.0;Ole DB Services=-4;Data Source=D:\test\test.mdb" ' //将获得的连接字符串赋值到
Set Cnn=CreateObject("ADODB.Connection") '//生成数据库连接对象
Cnn.Open strCnn ' //打开数据库
Set Rst=CreateObject("ADODB.Recordset") '//生成记录集对象
Rst.Open "select * from [user]" ,Cnn
Do While Not Rst.EOF
For iLen=1 to 3 '//我的表中只有3个字段,当然这种方法通用性不是很好
Select Case iLen
Case 1
strDb=strDb&Rst.Fields.item(iLen)&" "
Case 2
strDb=strDb&"+ "&Rst.Fields.item(iLen)&" "
Case 3
strDb=strDb&"= "&Rst.Fields.item(iLen)
End Select
Next
strDb=strDb&chr(13)
Rst.MoveNext
Loop
Rst.Close
cnn.close
msgbox strDb
Dim Cnn ,strDb,Rst,strCnn,ilen
strCnn="Provider=Microsoft.Jet.OLEDB.4.0;Ole DB Services=-4;Data Source=D:\test\test.mdb" ' //将获得的连接字符串赋值到
Set Cnn=CreateObject("ADODB.Connection") '//生成数据库连接对象
Cnn.Open strCnn
Set Rst=CreateObject("ADODB.Recordset")
Rst.Open "select * from [user]" ,Cnn
Do While Not
Rst.Close
cnn.close
msgbox strDb
三、连接Excel 表实例
DataTable.ImportSheet "D:\test\test.xls" ,1 ,"Global"
Set mysheet=datatable.GetSheet("Global")
mysheet.setcurrentrow (1)
c=mysheet.Getparameter(1).value
msgbox c
Set mysheet=datatable.GetSheet("Global")
mysheet.setcurrentrow (1)
c=mysheet.Getparameter(1).value
msgbox c
四、连接datatable
mysheet=DataTable.GetSheet("Global")
Val=mysheet.GetParameter(" pswd").ValueByRow( 3)
Msgbox val
Val=mysheet.GetParameter(" pswd").ValueByRow( 3)
Msgbox val
只是一部分,相关的还在整理!