Public Function daadfa()
'必须引用 ado --------- Microsoft ActiveX Date Objects X.X Library
Dim conn As New ADODB.Connection, connstr As String, db As String, rs As New ADODB.Recordset, i As Long, rows As Long
db = "C:\adb2.mdb"
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db
conn.Open connstr
rs.Open "select * from 表1", conn, 1, 3
'添加
rs.addnew
rs(1)="adsad1111"
rs.update
'jet sql 添加
conn.execute "insert into 表1 (field) values ('好啊')"
'删除
rs.delete
rs.update
'jet sql 删除
conn.execute "delete from 表1 where id=156"
'修改
rs(1)="dddd"
rs.update
'jet sql 修改
conn.execute "update 表1 set field1='dddd'"
'读取
If rs.EOF And rs.BOF Then
MsgBox "无记录"
Else
rows = 1
For i = 0 To rs.Fields.Count - 1
Worksheets("Sheet2").Cells(1, rows).value = rs.Fields(i).Name
Next i
Do Until rs.EOF
For i = 0 To rs.Fields.Count - 1
Worksheets("Sheet2").Cells(i + 2, rows).value = rs(i)
Next i
rows = rows + 1
rs.MoveNext
Loop
End If