VB中使用ADO代码向Access数据库添加记录

代码如下:

Option Explicit

'工程->引用->勾选 Microsoft ActiveX Data Objects 2.X Library

Dim Conn As New ADODB.Connection

Dim conStr As String

Dim Sql As String

Private Sub Command1_Click()

conStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & "book.mdb"

Conn.Open conStr

Sql = "insert into admin(aid,psw,realname)values('" & Text1.Text & " ','" & Text2.Text & " ','" & Text3.Text & "')"

Conn.Execute Sql

Conn.Close

End Sub