求用 VB(目前只有VB,没有其他软件…) 来实现 Access 数据库记录的查询,新增,保存,删除和修改功能。
1个回答
展开全部
在窗体添加Adodc控件一个text控件 一个添加记录按钮一个提交按钮在窗体设置代码:
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db1.mdb;Persist Security Info=False"
'设置数据库路径
Adodc1.CommandType = adCmdText
'设置记录源
Adodc1.RecordSource = "select * from message"
'连接数据库的message表文件Set Text1.DataSource = Adodc1text1.DataField = "姓名"End Sub
添加记录按钮代码:
Private Sub Command1_Click()Adodc1.Recordset.AddNew
'添加新纪录End Sub
提交代码:
Private Sub Command2_Click()
Adodc1.Recordset.Update;;
'保存
Adodc1.Refresh
'刷新
End Sub
首记录按钮的代码:
Private Sub sjl_Click()
Adodc1.Recordset.MoveFirst
End Sub
上一条记录按钮代码:
Private Sub up_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
End If
End Sub
下一条记录代码:
Private Sub down_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
末记录代码:
Private Sub mjl_Click()
Adodc1.Recordset.MoveLast
End Sub
删除记录代码:
Private Sub Command3_Click()
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
If (Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF) Then
MsgBox "已经无记录", , "提示"
End If
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db1.mdb;Persist Security Info=False"
'设置数据库路径
Adodc1.CommandType = adCmdText
'设置记录源
Adodc1.RecordSource = "select * from message"
'连接数据库的message表文件Set Text1.DataSource = Adodc1text1.DataField = "姓名"End Sub
添加记录按钮代码:
Private Sub Command1_Click()Adodc1.Recordset.AddNew
'添加新纪录End Sub
提交代码:
Private Sub Command2_Click()
Adodc1.Recordset.Update;;
'保存
Adodc1.Refresh
'刷新
End Sub
首记录按钮的代码:
Private Sub sjl_Click()
Adodc1.Recordset.MoveFirst
End Sub
上一条记录按钮代码:
Private Sub up_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
End If
End Sub
下一条记录代码:
Private Sub down_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
末记录代码:
Private Sub mjl_Click()
Adodc1.Recordset.MoveLast
End Sub
删除记录代码:
Private Sub Command3_Click()
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
If (Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF) Then
MsgBox "已经无记录", , "提示"
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询