【例10-1】 创建一个学生基本情况录入界面。
Private Sub Data1_Reposition()
Data1.Caption = "记录" & Data1.Recordset.AbsolutePosition + 1
 End Sub
Private Sub Data1_Validate(Action As Integer,Save As Integer)
If Save = True Then
mb = MsgBox("要保存吗?",vbYesNo,"保存记录")
If mb = vbNo Then
Save = False
Data1.UpdateControls
End If
End If
End Sub
Private Sub Edit_Click(Index As Integer)
Select Case Index
Case 0 '添加记录
Data1.Recordset.AddNew
Case 1 '删除记录
mb = MsgBox("要删除吗?",vbYesNo,"删除记录")
If mb = vbYes Then
Data1.Recordset.Delete
Data1.Recordset.MoveLast
End If
Case 2 '更新记录
Data1.UpdateRecord
Data1.Recordset.Bookmark = Data1.Recordset.LastModified
Case 3 '退出
Unload Me
End Select
End Sub
【例10-2】 利用ADO Data控件重新编写学生基本情况的输入程序。
Select Case Index
Case 0 '添加记录
Adodc1.Recordset.AddNew
Case 1 '删除记录
mb = MsgBox("要删除吗?",vbYesNo,"删除记录")
If mb = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveLast
End If
Case 2 '更新记录
Adodc1.Recordset.Update
Case 3 '上一条记录
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst
Case 4 '下一条记录
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
Case 5 '退出
Unload Me
End Select
【例10-3】 输入姓名查询成绩信息。
Private Sub CmmList_Click(Index As Integer)
Dim sqlstring As String
Select Case Index
Case 0
sqlstring = "select * from xscjb where " & _
"(((xscjb.学号) ='" & DataCombo1.BoundText & "'))"
Case 1
sqlstring = "select * from xscjb"
End Select
Adodc1.RecordSource = sqlstring
Adodc1.Refresh
End Sub