VB中adoc控件对数据库操作的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 17:19:11
Option Explicit
Public conn As New ADODB.Connection
Public Rs As New ADODB.Recordset

Private Sub Command1_Click()
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields("case") = Text1.Text
Adodc2.Recordset.Fields("time") = Text2.Text
Command1.Caption = "完成"
'MsgBox "成功添加记录!", vbOKOnly, "提示"

End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Adodc2.connectionstring = connectionstring
Adodc2.CommandType = adCmdText
Adodc2.CursorLocation = adUseClient
Adodc2.LockType = adLockPessimistic
Adodc2.RecordSource = "select * from sepclog"
Adodc2.Refresh
Text1.Text = ""
Text2.Text = ""
Command1.Caption = "添加"
End Sub

Public Function connectionstring() As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=

*帮你改了看可以吗?

1. 我帮你修改ConectionString(直接宣告成String)
2. 在Form_Load()事件加入Adodc2.CursorType = adOpenKeyset
3. 在Command1_Click()事件中加入Adodc2.Recordset.Update和
Adodc2.Refresh

Option Explicit
Public conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Dim connectionstring As String

Private Sub Command1_Click()
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields("case") = Text1.Text
Adodc2.Recordset.Fields("time") = Text2.Text
Adodc2.Recordset.Update
Adodc2.Refresh

Command1.Caption = "完成"
'MsgBox "成功添加记录!", vbOKOnly, "提示"

End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\asus\Desktop\manange\DATA.mdb;Persist Security Info=False"
Adodc2.connectionstrin