vb连接ACCESS数据库(急急!!!)

来源:百度知道 编辑:UC知道 时间:2024/05/28 06:01:54
在VB中建两个文本框TEXT1,TEXT2和一按钮button1,当单击按钮时把text1和text2中的文本写到数据库对应的字段中(user,password)中!

引用:Microsoft Activex Data Object 2.1 Library

Private Sub Command1_Click()
Dim Conn as New Adodb.Connection
Conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=D:\myDb.mdb" '修改成你的数据库路径
Dim SQL as String
SQL="Insert Into [数据表名](User,Password) Values('" & Text1.text & "','" & Text2.text & "')"
Conn.Execute SQL
Conn.Close
Set Conn=Nothing
End Sub