欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    最新vba数据库编程答案.doc

    • 资源ID:47988952       资源大小:208.50KB        全文页数:53页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    最新vba数据库编程答案.doc

    Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-datevba数据库编程答案循环语句VBA数据库编程技术实验目的1、 掌握connection对象2、 掌握Recordset对象3、 掌握Command对象实验题目9-1 connection对象的具体连接方法:方法1Dim conn As ADODB.Connection '定义对象类型Set conn = New ADODB.Connection '将对象初始化conn.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/access/vba数据库编程技术/学生成绩管理.mdb" '设置连接字符信息conn.open '连接对象打开.conn.Close '关闭连接对象Set conn = Nothing '将连接对象清空方法2Dim conn As ADODB.Connection '定义对象类型Set conn = New ADODB.Connection '将对象初始化conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/access/vba数据库编程技术/学生成绩管理.mdb;UID=;PWD=".conn.CloseSet conn = Nothing方法3Dim conn As ADODB.Connection '定义对象类型Set conn = New ADODB.Connection '将对象初始化conn.Open CurrentProject.Connection '打开当前正在连接的数据.conn.CloseSet conn = Nothing9-2 在9-1的基础上,打开表单学生信息,利用Recordset对象获取来自“学生成绩管理.mdb”中“学生”数据表的记录,并显示第一条记录。Private Sub Form_Load()Dim conn As ADODB.Connection '定义连接对象类型Dim rs As ADODB.Recordset '定义记录集对象类型Set rs = New ADODB.Recordset '将记录集对象初始化Set conn = New ADODB.Connection '将连接对象初始化conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/access/vba数据库编程技术/学生成绩管理.mdb;"rs.Open "select * from 学生", conn, adOpenKeyset, adLockReadOnlyrs.MoveFirstText0.Value = rs("姓名")Text2.Value = rs("学号")Text4.Value = rs("性别")conn.CloseSet conn = NothingEnd Sub9-3 打开表单增加专业,单击增加按钮增加一条关于专业的的新记录:专业编号:p07,专业名称:电子技术,专业负责人:刘容强。Private Sub Command0_Click()Dim conn As ADODB.Connection '定义连接对象类型Dim rs As ADODB.Recordset '定义记录集对象类型Set rs = New ADODB.Recordset '将记录集对象初始化Set conn = New ADODB.Connection '将连接对象初始化conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/access/vba数据库编程技术/学生成绩管理.mdb;"rs.Open "select * from 专业", conn, adOpenKeyset, adLockOptimisticrs.AddNewrs("专业编号") = "P07"rs("专业名称") = "电子技术"rs("专业负责人") = "刘容强"rs.UpdateMsgBox "已完成新记录的添加", 0 + 32, "提示"conn.CloseSet conn = NothingEnd Sub9-5新建一个过程a,将“专业”数据表中专业名称为“公共基础教学”的专业负责人姓名改为“郑智强”。Public Sub a()Dim conn As ADODB.Connection '定义对象类型Set conn = New ADODB.Connection '将对象初始化conn.Open CurrentProject.Connection '打开当前正在连接的数据Dim comm As ADODB.CommandSet comm = New ADODB.Commandcomm.ActiveConnection = conncomm.CommandText = "update 专业 set 专业负责人='郑智强' where 专业名称='公共基础教学'"comm.ExecuteMsgBox "已完成修改", 0 + 32, "提示"conn.CloseSet conn = NothingSet comm = NothingEnd Sub9-6打开“学生成绩管理.mdb”,设计课程成绩统计窗体,运行界面如图9-5所示,要求实现:1、在组合框combo1中选择一课程编号,则对应的课程名称、学分、任课教师、学时分别显示在对应文本框中2、单击“统计按钮”,则在对应文本框中显示指定课程的所有参考学生人数、课程平均分、60分以上人数和不及格人数。3、若未指定具体课程编号就单击“统计”按钮,则显示提示信息。Option Compare DatabasePrivate Sub Combo0_Change()Dim rs As ADODB.RecordsetSet rs = New ADODB.RecordsetDim sqlstr As Stringsqlstr = "select 课程名称,学时,学分,姓名 from 课程,教师 where 课程.教师编号=教师.教师编号 and 课程编号='" & Combo0 & "'"rs.Open sqlstr, CurrentProject.Connection, 2, 2If Not rs.EOF() ThenText4 = rs("课程名称")Text6 = rs("学分")Text8 = rs("姓名")Text10 = rs("学时")End Ifrs.CloseSet rs = NothingEnd SubPrivate Sub Command12_Click()Dim rs As ADODB.RecordsetSet rs = New ADODB.RecordsetDim sqlstr As Stringsqlstr = "select * from 成绩 where 课程编号='" & Combo0 & "'"rs.Open sqlstr, CurrentProject.Connection, 2, 2If Not rs.BOF() Or Not rs.EOF() Thensum = 0n = 0x = 0y = 0Do While Not rs.EOF()sum = sum + rs("成绩")n = n + 1If rs("成绩") >= 60 Then x = x + 1Else y = y + 1End Ifrs.MoveNextLoopaver = sum / nText15.Value = nText17.Value = Int(aver * 100 + 0.5) / 100Text19.Value = xText21.Value = yElse MsgBox "课程编号为空,请重新选择", 0 + 16, "提示"End Ifrs.CloseSet rs = NothingEnd Sub9-7 打开“学生成绩管理.mdb”,设计按课程查阅学生成绩窗体,运行界面如图9-7所示,要求实现如下:Public rs As ADODB.RecordsetPrivate Sub Combo0_Change()Dim rs As ADODB.RecordsetSet rs = New ADODB.RecordsetDim sqlstr As Stringsqlstr = "select 课程名称,学时,学分,姓名 from 课程,教师 where 课程.教师编号=教师.教师编号 and 课程编号='" & Combo0 & "'"rs.Open sqlstr, CurrentProject.Connection, 2, 2If Not rs.EOF() ThenText4 = rs("课程名称")Text6 = rs("学分")Text8 = rs("姓名")Text10 = rs("学时")End Ifrs.CloseSet rs = NothingEnd SubPrivate Sub Command12_Click()Set rs = New ADODB.RecordsetDim sqlstr As Stringsqlstr = "select 学生.学号,姓名,专业名称,成绩 from 学生,专业,成绩 where 学生.专业编号=专业.专业编号 " & _"and 成绩.学号=学生.学号 and 成绩.课程编号='" & Combo0.Value & "'"rs.Open sqlstr, CurrentProject.Connection, 2, 2If Not rs.BOF() Or Not rs.EOF() Then Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩") Command23.Enabled = True Command24.Enabled = True Command25.Enabled = True Command26.Enabled = TrueElse MsgBox "课程号为空,请重新指定课程编号", 0 + 16, "提示"End IfEnd SubPrivate Sub Command23_Click() rs.MoveFirst Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")End SubPrivate Sub Command24_Click()rs.MovePreviousIf Not rs.BOF() Then Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")Else rs.MoveNext Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩") MsgBox "已经是首记录", 0 + 64, "提示"End IfEnd SubPrivate Sub Command25_Click()rs.MoveNextIf Not rs.EOF() Then Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")Else rs.MovePrevious Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩") MsgBox "已经是未记录", 0 + 64, "提示"End IfEnd SubPrivate Sub Command26_Click() rs.MoveLast Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")End SubPrivate Sub Form_Activate()Command23.Enabled = FalseCommand24.Enabled = FalseCommand25.Enabled = FalseCommand26.Enabled = FalseEnd Sub9-8 在例9-7基础上,增加“更新”、“删除”、“新增”和“结束”4个命令按钮,运行界面如下图所示:Public rs As ADODB.RecordsetPrivate Sub Combo0_Change()Dim rs As ADODB.RecordsetSet rs = New ADODB.RecordsetDim sqlstr As Stringsqlstr = "select 课程名称,学时,学分,姓名 from 课程,教师 where 课程.教师编号=教师.教师编号 and 课程编号='" & Combo0 & "'"rs.Open sqlstr, CurrentProject.Connection, 2, 2If Not rs.EOF() ThenText4 = rs("课程名称")Text6 = rs("学分")Text8 = rs("姓名")Text10 = rs("学时")End Ifrs.CloseSet rs = NothingEnd SubPrivate Sub Command12_Click()Set rs = New ADODB.RecordsetDim sqlstr As Stringsqlstr = "select 学生.学号,姓名,专业名称,成绩 from 学生,专业,成绩 where 学生.专业编号=专业.专业编号 " & _"and 成绩.学号=学生.学号 and 成绩.课程编号='" & Combo0.Value & "'"rs.Open sqlstr, CurrentProject.Connection, 2, 2If Not rs.BOF() Or Not rs.EOF() Then Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩") Command23.Enabled = True Command24.Enabled = True Command25.Enabled = True Command26.Enabled = True Command27.Enabled = True Command28.Enabled = True Command29.Enabled = TrueElse MsgBox "课程号为空,请重新指定课程编号", 0 + 16, "提示"End IfEnd SubPrivate Sub Command23_Click() rs.MoveFirst Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")End SubPrivate Sub Command24_Click()rs.MovePreviousIf Not rs.BOF() Then Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")Else rs.MoveNext Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩") MsgBox "已经是首记录", 0 + 64, "提示"End IfEnd SubPrivate Sub Command25_Click()rs.MoveNextIf Not rs.EOF() Then Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")Else rs.MovePrevious Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩") MsgBox "已经是未记录", 0 + 64, "提示"End IfEnd SubPrivate Sub Command26_Click() rs.MoveLast Text15.Value = rs("学号") Text17.Value = rs("姓名") Text19.Value = rs("专业名称") Text21.Value = rs("成绩")End SubEnd SubPrivate Sub Command27_Click()flag = 0yn = MsgBox("确定更新成绩吗?", 1 + 32, "提问")If yn = 1 Then Set rs = New ADODB.Recordset Dim sqlstr As String sqlstr = "select * from 成绩" rs.Open sqlstr, CurrentProject.Connection, 2, 2 Do While Not rs.EOF() And flag = 0 If rs("学号") = Trim(Text15.Value) And rs("课程编号") = Trim(Combo0.Value) Then rs("成绩") = Text21.Value rs.Update MsgBox "完成成绩更新!", 0 + 64, "提示" flag = 1 Else rs.MoveNext End If Loop If flag = 0 Then MsgBox "学号或课程编号有变化,无法进行成绩更新!", 0 + 16, "提示" End If rs.Close Set rs = NothingEnd IfEnd SubPrivate Sub Command28_Click()flag = 0yn = MsgBox("确定删除本记录吗?", 1 + 32, "提问")If yn = 1 Then Set rs = New ADODB.Recordset Dim sqlstr As String sqlstr = "select * from 成绩" rs.Open sqlstr, CurrentProject.Connection, 2, 2 Do While Not rs.EOF() And flag = 0 If rs("学号") = Trim(Text15.Value) And rs("课程编号") = Trim(Combo0.Value) Then rs.Delete rs.Update MsgBox "已完成删除!", 0 + 64, "提示" Text15.Value = "" Text17.Value = "" Text19.Value = "" Text21.Value = "" Command23.Enabled = False Command24.Enabled = False Command25.Enabled = False Command26.Enabled = False flag = 1 Else rs.MoveNext End If Loop If flag = 0 Then MsgBox "学号或课程编号有变化,无法进行成绩更新!", 0 + 16, "提示" End If rs.Close Set rs = NothingEnd IfEnd SubPrivate Sub Command29_Click()cmark = 0smark = 0yn = MsgBox("确定新增成绩信息吗?", 1 + 32, "提问")If yn = 1 Then Set rs = New ADODB.Recordset Dim sqlstr As String sqlstr = "select * from 成绩 where 学号='" & Trim(Text15.Value) & "'and 课程编号='" & Combo0.Value & "'" rs.Open sqlstr, CurrentProject.Connection, 2, 2 If Not rs.BOF() And Not rs.EOF() Then MsgBox "成绩表已有记录,无法再新增", 0 + 64, "提示" cmark = 1 End If rs.Close Set rs = Nothing If cmark = 0 Then Set rs = New ADODB.Recordset sqlstr = "select * from 学生 where 学号='" & Trim(Text15.Value) & "'" rs.Open sqlstr, CurrentProject.Connection, 2, 2 If Not rs.BOF() And Not rs.EOF() Then smark = 1 Else MsgBox "新增学号不存在,无法新增", 0 + 64, "提示" End If rs.Close Set rs = Nothing If smark = 1 Then Set rs = New ADODB.Recordset sqlstr = "select * from 成绩" rs.Open sqlstr, CurrentProject.Connection, 2, 2 rs.AddNew rs("学号") = Trim(Text15.Value) rs("课程编号") = Trim(Combo0.Value) rs("成绩") = Text21.Value rs.Update MsgBox "完成新增操作", 0 + 64, "提示" rs.Close Set rs = Nothing Text15.Value = "" Text17.Value = "" Text19.Value = "" Text21.Value = "" Command23.Enabled = False Command24.Enabled = False Command25.Enabled = False Command26.Enabled = False End If End IfEnd IfEnd SubPrivate Sub Form_Activate()Command23.Enabled = FalseCommand24.Enabled = FalseCommand25.Enabled = FalseCommand26.Enabled = FalseCommand27.Enabled = FalseCommand28.Enabled = FalseCommand29.Enabled = FalseEnd Sub-

    注意事项

    本文(最新vba数据库编程答案.doc)为本站会员(1595****071)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开