发布网友 发布时间:2022-05-10 19:46
共2个回答
热心网友 时间:2023-07-21 11:09
Dim cn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset, rs2 As New ADODB.Recordset
Dim rs As New ADODB.Recordset
Private Sub Cmdadd_Click(Index As Integer)
Text1(0).Enabled = True
Text1(0).SetFocus
Data1.Recordset.AddNew '数据库新增命令
cmdfirst(0).Enabled = False '设定各个控件的可用属性
cmdpre(1).Enabled = False
cmdnext(2).Enabled = False
cmdlast(3).Enabled = False
Cmdadd(0).Enabled = False
cmddelete.Enabled = False
cmdsave(5).Enabled = True
cmdmend(4).Enabled = False
End Sub
Private Sub cmddelete_Click()
Dim i As Integer
i = MsgBox("真的要删除当前记录吗?", vbYesNo, "警告") '数据库的删除警告和相应命令
If i = 6 Then
Data1.Recordset.Delete
Data1.Refresh
Call Form_Load
End If
End Sub
Private Sub cmdExit_Click(Index As Integer)
End
End Sub
Private Sub cmdfirst_Click(Index As Integer)
If Not Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst '数据库移动到第一条
End If
End Sub
Private Sub cmdlast_Click(Index As Integer)
If Not Data1.Recordset.BOF Then
Data1.Recordset.MoveLast '数据库移动到最后一条
End If
End Sub
Private Sub cmdmend_Click(Index As Integer)
Text1(0).Enabled = True '设定各控件属性
cmdsave(5).Enabled = True
cmdmend(4).Enabled = False
End Sub
Private Sub cmdnext_Click(Index As Integer)
If Data1.Recordset.RecordCount <> 0 Then
If Data1.Recordset.EOF = False Then Data1.Recordset.MoveNext '数据库移动到下一条
If Data1.Recordset.EOF = True Then '判断数据库是否为最后一条
Data1.Recordset.MoveLast
MsgBox ("已经是最后一条")
End If
End If
End Sub
Private Sub cmdpre_Click(Index As Integer)
If Data1.Recordset.RecordCount <> 0 Then
If Data1.Recordset.BOF = False Then
Data1.Recordset.MovePrevious '数据库移动到上一条
End If
If Data1.Recordset.BOF = True Then '判断数据库是否为第一条
Data1.Recordset.MoveFirst
MsgBox ("已经是第一条")
End If
End If
End Sub
Private Sub cmdsave_Click(Index As Integer)
If Text1(0).Text = "" Or Text1(1).Text = "" Or Text1(2).Text = "" Or Text1(4).Text = "" Or Text1(5).Text = "" Then
MsgBox "请完善数据!", , "提示" '检测文本框中是否为空
Exit Sub
End If
' Data1.Recordset.MoveLast
Data1.UpdateRecord '保存更新数据库
MsgBox "数据保存成功!", , "提示"
cmdfirst(0).Enabled = True '设定个控件属性
cmdpre(1).Enabled = True
cmdnext(2).Enabled = True
cmdlast(3).Enabled = True
cmddelete.Enabled = True
cmdmend(4).Enabled = True
Call Form_Load
End Sub
Private Sub Comsx_Click()
Call Form_Load '点击刷新,重新加载界面
End Sub
Private Sub Form_Load()
Data1.Visible = False
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& App.Path & "\data.mdb;Persist Security Info=False" '打开数据库
rs1.Open "通讯录", cn, adOpenKeyset, adLockOptimistic '打开数据库中的表文件
If rs1.BOF Then
MsgBox " 已经没有数据" '判断有没有数据
Else
Set MSHFlexGrid1.DataSource = rs1 '数据在MSHFlexGrid1控件中显示
MSHFlexGrid1.ColWidth(0) = 100
MSHFlexGrid1.ColWidth(6) = 2200
End If
rs1.Close
'Set DataGrid1.DataSource = Adodc1
Cmdadd(0).Enabled = True
cmdsave(5).Enabled = False
Text1(0).Enabled = False
cmdfirst(0).Enabled = True '设定个控件属性
cmdpre(1).Enabled = True
cmdnext(2).Enabled = True
cmdlast(3).Enabled = True
cmddelete.Enabled = True
cmdmend(4).Enabled = True
Data1.Visible = False
cn.Close
End Sub
热心网友 时间:2023-07-21 11:10
选中控件 右键--属性-生成-Jet 4.0 ole 下一步--选择数据库路径-测试连接-确定 ---纪录源--选择表 或者输入SQL语句 看你命令类型选择