Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "office.mdb;Persist Security Info=False"
Dim userstr As String
userstr = "insert into table(ziduan1,ziduan2) values('shujv1','shujv2')"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = userstr
Adodc1.Refresh
Dim userstr As String
userstr = "insert into table(ziduan1,ziduan2) values('shujv1','shujv2')"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = userstr
Adodc1.Refresh
Adodc1.RecordSource = userstr
On Error Resume Next
Adodc1.Refresh
with conn
if .state=adstateopen then .close
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\office.mdb;Persist Security Info=False"
.open
end withconn.execute "insert into table(ziduan1,ziduan2) values('shujv1','shujv2')"
操作数据库要先连接,再操作.
在工程/引用中添加microsoft axtivex data object 2.0 library
然后
查询:
dim cn as adodb.connection
dim rs as adodb.recordset
set cn=createobject(adodb.connection)
set rs=createobject(adodb.recordset)
cn.connectstring="你的连接字符"
cn.open
rs.open "你的数据库查询语言",cn,3,1
rs.close
更新添加或删除dim cn as adodb.connection
cn.connectstring="你的连接字符"
cn.open
cn.execute "你的更新语句"
建议还是用adodb.connection来执行。