VB data控件的用法
做一个简单的应用data控件可对数据库进行添加,删除,查询操作的系统。请给出具体代码和注释,如果能给发个演示程序最好,高分悬赏。...
做一个简单的应用data控件可对数据库进行添加,删除,查询操作的系统。请给出具体代码和注释,如果能给发个演示程序最好,高分悬赏。
展开
1个回答
展开全部
Private Sub Command1_Click() '“上一个”按钮
Data1.Recordset.MovePrevious
Command2.Enabled = True
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
Command1.Enabled = False
End If
End Sub
Private Sub Command2_Click() '“下一个”按钮
Data1.Recordset.MoveNext
Command1.Enabled = True
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
Command2.Enabled = False
End If
End Sub
Private Sub Command3_Click() '“添加”按钮
Data1.Recordset.AddNew
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command3.Enabled = False
Text1.SetFocus
End Sub
Private Sub Command4_Click() '“删除”按钮
i = MsgBox("确定删除该记录", 52, "信息提示")
If i = 6 Then
Data1.Recordset.Delete
Data1.Refresh
End If
End Sub
Private Sub Command5_Click()
If Text6.Text = "" Then
MsgBox "请输入要查询的内容", 48, "信息提示"
Text6.SetFocus
Exit Sub
End If
If Combo1.Text = "姓名" Then
Data1.Recordset.FindFirst "姓名=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "固定电话" Then
Data1.Recordset.FindFirst "固定电话=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "移动电话" Then
Data1.Recordset.FindFirst "移动电话=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "QQ" Then
Data1.Recordset.FindFirst "QQ=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "E_Mail" Then
Data1.Recordset.FindFirst "E_Mail=" & "'" & Text6.Text & "'"
End If
If Data1.Recordset.NoMatch Then
MsgBox "无该记录", 64, "信息提示"
End If
End Sub
Private Sub Command6_Click() '“确定”按钮
On Error GoTo errorhandler
Data1.UpdateRecord
Data1.Recordset.MoveLast
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Exit Sub
errorhandler:
If Err.Number = 524 Then
MsgBox "重复记录!", 48, "信息提示"
End If
Resume
End Sub
Private Sub Form_Load()
Combo1.Text = Combo1.List(0)
End Sub
Data1.Recordset.MovePrevious
Command2.Enabled = True
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
Command1.Enabled = False
End If
End Sub
Private Sub Command2_Click() '“下一个”按钮
Data1.Recordset.MoveNext
Command1.Enabled = True
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
Command2.Enabled = False
End If
End Sub
Private Sub Command3_Click() '“添加”按钮
Data1.Recordset.AddNew
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command3.Enabled = False
Text1.SetFocus
End Sub
Private Sub Command4_Click() '“删除”按钮
i = MsgBox("确定删除该记录", 52, "信息提示")
If i = 6 Then
Data1.Recordset.Delete
Data1.Refresh
End If
End Sub
Private Sub Command5_Click()
If Text6.Text = "" Then
MsgBox "请输入要查询的内容", 48, "信息提示"
Text6.SetFocus
Exit Sub
End If
If Combo1.Text = "姓名" Then
Data1.Recordset.FindFirst "姓名=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "固定电话" Then
Data1.Recordset.FindFirst "固定电话=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "移动电话" Then
Data1.Recordset.FindFirst "移动电话=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "QQ" Then
Data1.Recordset.FindFirst "QQ=" & "'" & Text6.Text & "'"
ElseIf Combo1.Text = "E_Mail" Then
Data1.Recordset.FindFirst "E_Mail=" & "'" & Text6.Text & "'"
End If
If Data1.Recordset.NoMatch Then
MsgBox "无该记录", 64, "信息提示"
End If
End Sub
Private Sub Command6_Click() '“确定”按钮
On Error GoTo errorhandler
Data1.UpdateRecord
Data1.Recordset.MoveLast
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Exit Sub
errorhandler:
If Err.Number = 524 Then
MsgBox "重复记录!", 48, "信息提示"
End If
Resume
End Sub
Private Sub Form_Load()
Combo1.Text = Combo1.List(0)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询