《Visual Basic程序设计》课程作业(四)
第6章 数据库应用——学生信息管理
1.单项选择题
(1) ADO控件属于ActiveX控件,使用之前必须Microsoft ADO Data Conctrol 6.0(OLE DB)其添加到工具箱中,添加ADO控件的菜单为( )。
A.“工程”→“引用”
B.“工程”→“部件”
C.“工具”→“选项” D.“工程”→“添加文件”
(2)利用ADO访问数据库,首先要创建一个( )对象,用于建立和数据库的连接。
A.Connection对象
B.Recordset对象
C.Command对象 D.Object对象
(3)SQL语言的Select语句中,用于分组的语句为( )。 A.where B.group by C.order by (4)以下四个控件,不属于数据绑定控件的是( )。 A.Text控件 2.程序阅读题
(1)说明下面的主要功能
Dim Adocn As Connection Set Adocn = New Connection
' '
D.having D.Label控件
B.DataGrid控件 C.Option控件
Adocn.Open \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\vb\\SMS\\xs.mdb\" '
(2)说明下面的主要功能
Dim ADOrs As New Recordset ' ADOrs.ActiveConnection = ADOcn ' strSQL = \"select * from 学生表\" ' ADOrs.Open strSQL ' ADOrs.Close '
3.程序设计题
(1)有以下3个数据表:
学生表:student_info(student_id,student_name,student_sex,student_class),分别表示学号、姓名、性别、班级,各字段数据类型都是文本。
课程表:course_info(course_ID ,course_name ,course_credit),分别表示课程号、课程名、学分,课程号、课程名为文本类型,学分为数字类型。
成绩表:mark_info(student_ID, course_ID,mark),分别表示学号、课程号、成绩,其中
学号、课程号为文本类型,mark为数字类型。
写出下列功能的SQL语句:
① 插入一个新课程记录(课程号:A001;课程名:英语1;学分:5) ② 修改学号为“95020”,课程号为“A001”的成绩为85
③ 查询所有学生的基本信息,使用中文作为查询结果的各字段的名称 ④ 统计出各个班级的人数
⑤ 查询出学号为“95020”所选修的课程名和成绩,以及姓名
(2)编写使用ADO对象中的Connection对象连接SQL Server数据库的代码。 (3)使用Visual Basic开发一个简单的通讯录,要求实现以下功能:
① 能够录入联系人的基本信息,并保存。 ② 输入后,可以浏览所有联系人的基本信息。 ③ 可以按姓名等关键字查找记录。
④ 能够对个人的基本信联系人息进行编辑修改和删除记录。
第7章 多媒体应用——播放器
1.单项选择题
(1)决定系统是否自动检测多媒体控件(MMControl)各按钮的状态的属性是( )。
A.Enable
B.AutoEnable
C.PlayEnabled D.以上答案都不正确
(2)将多媒体控件(MMControl)的Frames属性设为3,则以下叙述正确的是( )。
A.指定Back或Step命令后退或前进的帧数都为3 B.只有Back命令后退的帧数为3 C.只有Step命令前进的帧数为3
D.后退或前进的帧数都为6
(3)多媒体控件(MMControl)具有一组执行MCI命令的下压式按钮。其中Record按钮表示为( )。 A.前一首 B.录制 C.弹出 D.播放
(4)为了使多媒体控件(MMControl)中的录制按钮不显示,应添加代码( )。
A.MMControl1.Visible= False B.MMControl1.Visible= True C.MMControl1.RecordVisible= False
D.MMControl1.RecordVisible= True
(5)在多媒体控件(MMControl)中,DeviceType属性用于设置多媒体设备的类型,如果将要播放的文件是CD歌曲,应将DeviceType属性设置为( )。
A.DigitalVideo B.WaveAudio C.AVIVideo D.CDAudio (6)Windows Media Player控件的UiMode属性,表示播放器界面模式,以下选项是播放器模式的属性值是( )。
A.Full
B.Mini
C.None
D.以上都是
(7)在Windows Media Player控件中,决定播放文件是否全屏的属性是( )。 A.FullScreen 2.程序设计题
B.Full
C.Screen
D.stretchToFit
设计CD播放器程序,通过该程序能够欣赏CD-ROM中CD曲目,并能控制播放状态及更改播放曲目,显示CD盘中的歌曲总数及正在播放歌曲的播放总时间,界面如下图所示。
参
第6章 数据库应用——学生信息管理
1.单项选择题 (1)B (2)A 2.程序阅读题 (1)
声明Connection对象Adocn 创建新对象 建立与数据库连接
(2)
声明并创建一个新的Recordset对象 与Connection对象建立关联 声明一条SQL语句
执行SQL语句,记录集为查询结果 关闭记录集对象
3.程序设计题 (1)
① Insert into course_info values ('A001', '英语', 5)
② Update mark_info set mark=85 where student_ID ='95020' and course_ID ='A001' ③ Select student_id as 学号, student_name as 姓名, student_sex as 性别, student_class as
(3)B
(4)C
班级 from student_info
④ Select student_class ,count(*) from student_info group by student_class ⑤ Select student_name as 姓名, course_name as 课程名, mark as成绩from student_info,
course_info, mark_info
where student_info. student_id = mark_info. student_id
and course_info. course_ID = mark_info. course_ID and student_info. student_id ='95020'
(2)
Public ADOcn As Connection Public Sub Main()
Dim strSqlServer As String
strSqlServer=\"Provider=SQLOLEDB;Server=(local);User ID=sa; _
Password=sa; Database=XS\" If ADOcn Is Nothing Then
Set ADOcn = New Connection
ADOcn.Open strSqlServer '连接SQL Server数据库
End If End Sub
(3)
Frmmain窗体
Private Sub Form_Load() Combo1.AddItem \"姓名\" Combo1.AddItem \"手机\" End Sub
Private Sub modify_Click()
If DataGrid1.Visible = False Then frmadd.Show Else
frmupdate.Show End If End Sub
Private Sub new_Click() frmadd.Show End Sub
Private Sub quit_Click() End End Sub
Private Sub refesh_Click() Dim strSQL As String
strSQL = \"select * from address_list \" Adodc1.RecordSource = strSQL Adodc1.Refresh DataGrid1.Visible = True DataGrid1.Refresh End Sub frmadd窗体
Private Sub about_Click() frmabout.Show End Sub
Private Sub Command1_Click() Dim strSQL As String If Combo1.Text = \"姓名\" Then If Text1.Text = \"\" Then
MsgBox \"请输入要查询的姓名\ Else
strSQL = \"select *\"
strSQL = strSQL + \" from address_list where name='\" + Text1.Text + \"'\"
Adodc1.RecordSource = strSQL Adodc1.Refresh DataGrid1.Visible = True End If End If
If Combo1.Text = \"手机\" Then If Text1.Text = \"\" Then
MsgBox \"请输入要查询的手机\ Else
strSQL = \"select *\"
strSQL = strSQL + \" from address_list where mobile='\" + Text1.Text + \"'\"
Adodc1.RecordSource = strSQL Adodc1.Refresh DataGrid1.Visible = True End If End If End Sub
Private Sub DataGrid1_Click()
Adodc1.Caption = \" 第[\" + DataGrid1.Text + \"]记录\" End Sub
Private Sub delete_Click() DataGrid1.Visible = True
If MsgBox(\"是否要删除?\esNo) = vbYes Then strSQL = \"Delete From address_list \"
strSQL = strSQL + \"Where 编号=\" + DataGrid1.Text ADOcn.Execute strSQL
MsgBox \"删除成功\ End If
Adodc1.Refresh End Sub
Private Sub Form_Load() Combo1.AddItem \"姓名\" Combo1.AddItem \"手机\" End Sub
Private Sub modify_Click()
If DataGrid1.Visible = False Then frmadd.Show Else
frmupdate.Show End If End Sub
Private Sub new_Click() frmadd.Show End Sub
Private Sub quit_Click() End End Sub
Private Sub refesh_Click() Dim strSQL As String
strSQL = \"select * from address_list \" Adodc1.RecordSource = strSQL
Adodc1.Refresh DataGrid1.Visible = True DataGrid1.Refresh End Sub
frmupdate窗体
Private Sub Command1_Click() Dim strSQL As String
strSQL = \"update address_list set name='\" + Text1.Text strSQL = strSQL + \"',sex='\" + Combo1.Text strSQL = strSQL + \"',mobile='\" + Text3.Text strSQL = strSQL + \"',phone='\" + Text4.Text strSQL = strSQL + \"',QQ='\" + Text5.Text strSQL = strSQL + \"',Email='\" + Text6.Text strSQL = strSQL + \"',address='\" + Text7.Text
strSQL = strSQL + \"' where id=\" + frmmain.DataGrid1.Text ADOcn.Execute strSQL
MsgBox \"修改成功!\ frmmain.Adodc1.Refresh End Sub
Private Sub Command2_Click() Unload Me End Sub
Private Sub Form_Load() Text1.Text = \"\" Combo1.AddItem \"男\" Combo1.AddItem \"女\" Text3.Text = \"\" Text4.Text = \"\" Text5.Text = \"\" Text5.Text = \"\" Text6.Text = \"\" Text7.Text = \"\"
Dim ADOrs As New Recordset ADOrs.ActiveConnection = ADOcn
ADOrs.Open \"select * from address_list where id=\" + frmmain.DataGrid1.Text Text1.Text = ADOrs.Fields(\"name\") Combo1.Text = ADOrs.Fields(\"sex\") Text3.Text = ADOrs.Fields(\"mobile\")
Text4.Text = ADOrs.Fields(\"phone\") Text5.Text = ADOrs.Fields(\"QQ\") Text6.Text = ADOrs.Fields(\"Email\") Text7.Text = ADOrs.Fields(\"address\") End Sub
Module1模块
'声明全局对象变量ADOcn,用于创建与数据库的连接 Public ADOcn As Connection Public Sub Main()
'定义数据库连接字符串 Dim strAccess As String
'用于连接Access数据库,其中Data Source为具体的数据库文件路径,其他设置不变
strAccess = \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=通讯录.mdb\"
'如果还没有建立与数据库的连接,则用以下代码创建。 If ADOcn Is Nothing Then Set ADOcn = New Connection
'ADOcn.Open strSQLServer '连接SQL Server数据库 ADOcn.Open strAccess '连接Access数据库 '如果希望连接Access数据库,则使用strAccess
'无论你使用的是何种数据库,只需改变此处设置,其他程序代码基本不用改变
End If
frmmain.Show '显示主窗体 End Sub
第7章 多媒体应用——播放器
1.单项选择题 (1)B
(2)A
(3)B
(4)C
(5)D
(6)D (7)D 2.程序设计题
Private Sub Form_Load() '初始化设备
MMControl1.Visible = False MMControl1.Notify = True MMControl1.Shareable = False MMControl1.TimeFormat = 0 MMControl1.DeviceType = \"cdaudio\" MMControl1.UpdateInterval = 1000 End Sub
Private Sub MMControl1_StatusUpdate() '计算曲目信息
label2.Caption = \"曲目总数:\" & MMControl1.Tracks
Label3.Caption = \"曲目播放总时间:\" & Trim(Str(Int(MMControl1.Length / 60000))) + \"分\"
Label4.Caption = \"正在播放曲目:\" & MMControl1.Track End Sub
Private Sub ComPlay_Click() '开始播放
MMControl1.Command = \"play\" ComPause.Enabled = True ComPlay.Enabled = False ComStop.Enabled = True End Sub
Private Sub ComPrev_Click() '播放上一首
MMControl1.Command = \"prev\" End Sub
Private Sub ComNext_Click() '播放下一首
MMControl1.Command = \"next\" End Sub
Private Sub ComPause_Click() '暂停播放
MMControl1.Command = \"pause\" ComPlay.Enabled = True ComPause.Enabled = True End Sub
Private Sub ComStop_Click() '停止播放
MMControl1.Command = \"stop\" ComStop.Enabled = False ComPlay.Enabled = True End Sub
Private Sub ComEject_Click() '弹出
MMControl1.Command = \"stop\" MMControl1.Command = \"eject\" ComPlay.Enabled = True End Sub
Private Sub ComEnd_Click() '退出 End End Sub
Private Sub Form_Unload(Cancel As Integer) '关闭MCI设备
MMControl1.Command = \"stop\" MMControl1.Command = \"close\" End Sub
因篇幅问题不能全部显示,请点此查看更多更全内容