如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
第16章VB数据库应用编程示例图16-1对象名"查找"按钮程序代码如下:PrivateSubCmdSearch_Click()IfLen(TxtSearchDept.Text)>0ThenAdodcStudent.CommandType=adCmdTextAdodcStudent.RecordSource=_"select*fromstudentwhereSdept='"&_Trim(TxtSearchDept.Text)&"'"AdodcStudent.RefreshElseMsgBox("请指定要查找的系")EndIfEndSub16.2示例2程序代码如下:(1)窗体启动时的初始化代码PrivateSubForm_Load()'初始时使“取消”按钮为不可用状态CmdCancel.Enabled=FalseEndSub(2)数据操作按钮组代码“添加”按钮代码:PrivateSubCmdAdd_Click()AdodcStudent.Recordset.AddNew'使“添加”和“删除”按钮为不可用状态CmdAdd.Enabled=FalseCmdDel.Enabled=False'使“更改”和“取消”按钮为可用状态CmdUpdate.Enabled=TrueCmdCancel.Enabled=TrueEndSub“取消”按钮代码:PrivateSubCmdCancel_Click()AdodcStudent.Recordset.CancelUpdate'使"添加"和"删除"按钮为可用状态CmdAdd.Enabled=TrueCmdDel.Enabled=True'使"取消"按钮为不可用状态CmdCancel.Enabled=FalseEndSub“删除”按钮代码:PrivateSubCmdDel_Click()DimresAsIntegerres=MsgBox("确实要删除此行记录吗?",_vbExclamation+vbYesNo+vbDefaultButton2)Ifres=vbYesThenAdodcStudent.Recordset.DeleteAdodcStudent.Recordset.MoveNextIfAdodcStudent.Recordset.EOF=TrueThenAdodcStudent.Recordset.MoveLastEndIfEndIfEndSub“更新”按钮代码:PrivateSubCmdUpdate_Click()'将文本框中的当前值写入结果集相应字段中AdodcStudent.Recordset.Fields("Sno")=Trim(TxtSno.Text)AdodcStudent.Recordset.Fields("Sname")=Trim(TxtSname.Text)AdodcStudent.Recordset.Fields("Ssex")=Trim(TxtSsex.Text)AdodcStudent.Recordset.Fields("Sage")=CInt(Trim(TxtSage.Text))AdodcStudent.Recordset.Fields("Sdept")=Trim(TxtSdept.Text)'使更新生效AdodcStudent.Recordset.UpdateCmdAdd.Enabled=TrueCmdDel.Enabled=TrueCmdCancel.Enabled=FalseEndSub(3)移动指针方法组代码PrivateSubCmdFirst_Click()AdodcStudent.Recordset.MoveFirstEndSubPrivateSubCmdPrevious_Click()AdodcStudent.Recordset.MovePreviousIfAdodcStudent.Recordset.BOF=TrueThenAdodcStudent.Recordset.MoveFirstEndIfEndSubPrivateSubCmdLast_Click()AdodcStudent.Recordset.MoveLastEndSubPrivateSubCmdNext_Click()AdodcStudent.Recordset.MoveNextIfAdodcStudent.Recordset.EOF=TrueThenAdodcStudent.Recordset.MoveLastEndIfEndSub1316.3示例3PrivateSubForm_Load()DimstrSnoAsStringDim