Option Explicit'工程->引用->Microsoft ActiveX Data Objects 2.0 Library (后面为版本号)
Dim cn As New ADODB.Connection
Dim rs As New ADODB.RecordsetPrivate Sub Command1_Click()
'读取
rs.Open "SELECT * FROM TABLENAME WHERE NAME = '" & txtName.Text & "'", cn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Label1.Caption = rs!ID
Label2.Caption = rs!Memo
End If '添加
rs.AddNew
rs!ID = "编号"
rs!Memo = "备注"
rs.Update '删除
cn.Execute "DELETE FROM TABLENAME"
End SubPrivate Sub Form_Load()
cn.ConnectionString = ""
cn.Open
'查询字符串可以上这里查
'http://www.connectionstrings.com/
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Dim cn As New ADODB.Connection
Dim rs As New ADODB.RecordsetPrivate Sub Command1_Click()
'读取
rs.Open "SELECT * FROM TABLENAME WHERE NAME = '" & txtName.Text & "'", cn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Label1.Caption = rs!ID
Label2.Caption = rs!Memo
End If '添加
rs.AddNew
rs!ID = "编号"
rs!Memo = "备注"
rs.Update '删除
cn.Execute "DELETE FROM TABLENAME"
End SubPrivate Sub Form_Load()
cn.ConnectionString = ""
cn.Open
'查询字符串可以上这里查
'http://www.connectionstrings.com/
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
http://www.knowsky.com/4168.html
参考此贴中我转贴的文章。http://community.csdn.net/Expert/topic/3094/3094767.xml?temp=.2957727