vb+access实现添加删除修改,送200分。

2024-11-24 11:45:17
推荐回答(1个)
回答1:

'如果你还没连接数据库
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\data.mdb;Persist Security Info=False" '设置数据库路径
Adodc1.CommandType = adCmdText '设置记录源
Adodc1.RecordSource = "select * from userinfo" '连接数据库的userinfo表文件
End Sub

'如果你已经通过Adodc控件Adodc1连接好了数据库
Private Sub Button1_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset("姓名") = TextBox1
Adodc1.Recordset("地址") = TextBox2
Adodc1.Recordset("手机") = TextBox3
Adodc1.Recordset.Update
End Sub

Private Sub Button2_Click()
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
IF Adodc1.Recordset("姓名") = TextBox1 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Exit Do
End IF
Loop
End Sub

Private Sub Button3_Click()
Button2_Click
Button1_Click
End Sub