VB环境中如何修改保存记录?用命令按钮实现.

来源:百度知道 编辑:UC知道 时间:2024/09/22 05:13:12

Private Sub Command9_Click()
If tt1.Text <> "" Then
cnnUser.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\db.mpp"
cnnUser.Open
With rstUser
Set .ActiveConnection = cnnUser
.CursorType = adOpenKeyset 'adOpenKeyset,adOpenStatic可使用Recordset的RecordCount,其他两个属性不行
End With
With rstUser
If .State = adStateOpen Then .Close
.Open "Select * from [food] where mz = '" & tt1.Text & "'"
If Not .EOF Then
MsgBox "数据已存在!", vbOKOnly, "提示:"
tt1.Text = ""
.Close
cnnUser.Close
Exit Sub
End If
.Close
End With

With rstUser
If .State = adStateOpen Then .Close
.Open "Select * from [food]", cnnUser, adOpenKeyset, adLockOptimistic
.Add