代码分享:
Private Sub CmdAddRecord_Click()
Dim sc As Integer
Dim strsql As String
If Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
MsgBox ("请填入完整的信息")
Else
sc = MsgBox("确定要添加记录吗?", vbOKCancel, "提示")
If (sc = 1) Then
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str1 As String
Dim str2 As String
Dim str3 As String
str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
str2 = "Data Source=C:\Users\Administrator\Desktop\新建 Microsoft Access 数据库.mdb;"
str3 = "Jet OLEDB:Database Password="
conn.Open str1 & str2 & str3
strsql = "select * from 网站系统"
rs.Open strsql, conn, 3, 3
rs.AddNew
rs(1) = Text2.Text
rs(2) = Text3.Text
rs(3) = Text4.Text
rs.Update
rs.Close
conn.Close
MsgBox ("添加成功")
Adodc1.Refresh
End If
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End If
End Sub