1、模拟考题答案考前复习注意事项:1、还原数据库时一定要还原sql2005c2.bak文件,还原的名字为SQLZJ,登陆SQL2005时的服务器名为:localhost。2、对照着每个题的视频,先一个一个题的做,最后再完整的做一次模拟题(共10题)3、前三个选项卡的题目,每个选项卡中一定要最先做在各文本框中显示数据的那个题。4、考试完成后一定要按要求备份数据库,内含题目至少30分。5、有导航条的那个考题,需保证它的数据表要最先从数据源中拖出来。(只有第一次拖出来的数据才会产生导航条)目录1、利用数据源方法,在“客户信息查询”选项卡,显示客户表的相关信息 22、用DataReader方法,在“客户信
2、息查询”选项卡,显示客户表的相关信息 23、在“客户信息查询”选项卡,在表格中显示客户信息 44、在“客户信息查询”选项卡,多个文本框进行模糊查询(方法1:一次完成设置) 54、在“客户信息查询”选项卡,多个文本框进行模糊查询(方法2:逐个设置) 85、在“客户信息查询”的表格中删除一条记录 116、用DataReader方法,在“产品管理”选项卡中显示产品信息 127、利用数据源方法,在“产品管理”选项卡中显示产品信息 148、在“产品管理”的选项卡,对产品表进行添加(方法1:直接利用添加按钮编程) 159、在“产品管理”选项卡,对产品表进行添加(方法2:借助insertcommand) 1
3、710、在“产品管理”选项卡,对产品表进行编辑 2011、在“产品管理”选项卡,对产品表进行删除 2212、在“销售订单管理”选项卡,用表格显示数据信息 2313、在“销售订单管理”中,显示多表信息并在表格显示数据 2314、在“销售订单管理”的选项卡中,进行“添加”操作 2515、在“销售订单管理”中,对表格中的数据进行“删除”操作 2916、在“库存管理”选项卡,创建“按类查询”的存储过程 3017、在“库存管理”选项卡,按类查询(用报表显示查询) 3118、在“库存管理”的选项卡,按供应商查询(用报表显示查询) 3319、在“库存管理”的选项卡中,“按产品查询” 3420、在“产品管理”
4、选项卡,创建“相关销售情况”的视图V1 3621、在“产品管理”选项卡,创建“相关销售情况”带参数(产品id,起始日期,终止日期)的存储过程:(以要货日期为准) 3722、在“产品管理”中,查询产品的“相关销售情况”(方法1: 直接利用视图v1) 3823、在“产品管理”中,查询产品的“相关销售情况”(方法2:利用视图和存储过程) 4024、在“产品管理”选项卡,利用视图直接查询产品的“相关库存情况” 421、利用数据源方法,在“客户信息查询”选项卡,显示客户表的相关信息解题步骤:1、在数据源sqlzjds中添加表customers:数据-显示数据源右击sqlzjDs使用向导配置数据集. 选择
5、数据库表对象customers-完成。(注意:如果没有数据集sqlzjds,就建立一个连接SqlzjCn下的含有表customers的数据集sqlzjds,但SqlzjCn连接控件在整个考试过程中只能建立一次)2、拖数据源sqlzjds中的customers到“客户信息查询”选项卡,删除自动生成的表格对象,保留导航条对象。(只保留customersBindingSource和customersTableAdapter对象)1、 绑定窗体上的各个控件:文本框Textbox的databindings的“Text”属性设为“customersBindingSource 相应字段”; 4、运行看结果。
6、2、用DataReader方法,在“客户信息查询”选项卡,显示客户表的相关信息1. 打开考试目录下的项目“sqlzj2005.vbproj”,选择“”的选项卡,要求:用SqlDataReader将数据库“sqlzj”中表“Customers”的第一条记录显示在相应的TextBox中,如下图所示。(10分) 操作步骤: 1、引入命名空间Imports System.DataImports System.Data.SqlClient2、补充定义如下类级(Public Class)变量:(如果前面已经定义过了,这里就不能重复定义了)Dim cn As SqlConnection Dim cmd As
7、 SqlCommandDim dr As SqlDataReader2、在form1_Load中补充如下代码段Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn = New SqlConnection(data source =.;initial catalog=sqlzj;integrated security =true) cmd = New SqlCommand(select top 1 * from customers, cn)
8、 cn.Open() dr = cmd.ExecuteReader If dr.IsClosed = False Then dr.Read() TextBox1.Text = dr.Item(客户ID).ToString TextBox2.Text = dr.Item(公司名).ToString TextBox3.Text = dr.Item(地址).ToString TextBox4.Text = dr.Item(城市).ToString TextBox5.Text = dr.Item(区域).ToString TextBox6.Text = dr.Item(国家).ToString Tex
9、tBox7.Text = dr.Item(邮编).ToString TextBox8.Text = dr.Item(电话).ToString TextBox9.Text = dr.Item(传真).ToString TextBox10.Text = dr.Item(联系人).ToString TextBox11.Text = dr.Item(联系人职务).ToString End If dr.Close() cn.Close()3、在“客户信息查询”选项卡,在表格中显示客户信息2. 添加一个新数据源,要求:与恢复好的数据库“sqlzj”连接,选择表“Customers”,连接名为“sqlzjC
10、n”,DataSet名为“sqlzjDs”;选择“客户信息查询”的选项卡,从刚建的数据连接中,将表“Customers”拖到该选项卡的空白处,如下图(1)所示;运行后应该如下图(2)所示:(10分)(1)(2)操作步骤:1、 添加一个新数据源sqlzjDs:数据-添加新数据源-数据库-microsoft SQL-新建连接(服务器名:本机形式:localhost;数据库选择:SQLZJ)-是,将连接保存为:sqlzjCn-选择数据库对象表Customers,输入DataSet名称为:sqlzjDs-完成。注意:新建连接在整个考试过程中只有一次,如果前面的题目已经做过这一步了,在这里就直接选择sq
11、lzjCn这个连接就可以了,后面的选择数据库对象的操作是一样的。2、数据-显示数据源-从数据源sqlzjDs中拖表Customers到设计窗体中。(设计窗体中自动出现导航条、表格Customersdataview等控件。)3、调整导航条的位置,不要覆盖窗体的运行标签;调整表格的位置和大小到合适程度。(注意:因为导航条只有在第一次从数据源中拖表的时候才产生,所以做本题时一定要保证是第一次拖数据源中的表。)4、运行调试。表格中自动显示出Customers表的内容。4、在“客户信息查询”选项卡,多个文本框进行模糊查询(方法1:一次完成设置)在“客户信息查询”的选项卡,进行合适的编程,要求:单击“重置
12、”按钮后,文本框(TextBox)中的内容清空;在任意的文本框(TextBox)中键入要查询的内容,再按“查询”按钮,则“CustomersDataGridView”会把查询结果显示出来,如下图所示。注意:要满足多条件、模糊查询的要求。(20分)解题步骤:Public Class Form1 Dim str As String1. 首先在“Form1.vb”的设计窗口模式双击“重置”按钮,进行如下所示的编程: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
13、 Button2.Click Me.TextBox1.Text = Me.TextBox2.Text = Me.TextBox10.Text = Me.TextBox11.Text = Me.TextBox3.Text = Me.TextBox4.Text = Me.TextBox5.Text = Me.TextBox7.Text = Me.TextBox6.Text = Me.TextBox8.Text = Me.TextBox9.Text = Str= End Sub2. 然后在“Form1.vb”的设计窗口模式双击“查询”按钮,进行如下所示的编程: Private Sub Button1
14、_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text Then str = 客户ID like + TextBox1.Text + % End If If TextBox2.Text Then If str = Then str = 公司名 like + TextBox2.Text + % Else str = str + and 公司名 like + TextBox2.Text + % End If End If If TextBox3
15、.Text Then If str = Then str = 地址 like + TextBox3.Text + % Else str = str + and 地址 like + TextBox3.Text + % End If End If If TextBox4.Text Then If str = Then str = 城市 like + TextBox4.Text + % Else str = str + and 城市 like + TextBox4.Text + % End If End If If TextBox5.Text Then If str = Then str = 区域
16、like + TextBox5.Text + % Else str = str + and 区域 like + TextBox5.Text + % End If End If If TextBox6.Text Then If str = Then str = 国家 like + TextBox6.Text + % Else str = str + and 国家 like + TextBox6.Text + % End If End If If TextBox7.Text Then If str = Then str = 邮编 like + TextBox7.Text + % Else str
17、= str + and 邮编 like + TextBox7.Text + % End If End If If TextBox8.Text Then If str = Then str = 电话 like + TextBox8.Text + % Else str = str + and 电话 like + TextBox8.Text + % End If End If If TextBox9.Text Then If str = Then str = 传真 like + TextBox9.Text + % Else str = str + and 传真 like + TextBox9.Tex
18、t + % End If End If If TextBox10.Text Then If str = Then str = 联系人 like + TextBox10.Text + % Else str = str + and 联系人 like + TextBox10.Text + % End If End If If TextBox11.Text Then If str = Then str = 联系人职务 like + TextBox11.Text + % Else str = str + and 联系人职务 like + TextBox11.Text + % End If End If
19、Me.CustomersBindingSource.Filter = str Me.CustomersDataGridView.Refresh()Str= 注意:记录的字段和相应的文本框要仔细地一一对应,千万不要写错;使用“like”命令可以达到模糊查询的要求。4、在“客户信息查询”选项卡,多个文本框进行模糊查询(方法2:逐个设置)3. 在“客户信息查询”的选项卡,进行合适的编程,要求:单击“重置”按钮后,文本框(TextBox)中的内容清空;在任意的文本框(TextBox)中键入要查询的内容,再按“查询”按钮,则“CustomersDataGridView”会把查询结果显示出来,如下图所示。
20、注意:要满足多条件、模糊查询的要求。(20分)操作步骤:(做本题的前提是:客户信息已经在每个文本框中显示出来了!窗口中的表格也已经正常显示数据了!)1、补充定义类级变量:Public Class Form1 Dim str As String2、重置按钮的事件代码如下:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = TextBox2.Text = TextBox3.Text = TextBox4.
21、Text = TextBox5.Text = TextBox6.Text = TextBox7.Text = TextBox8.Text = TextBox9.Text = TextBox10.Text = TextBox11.Text = 3、先设置str初始为空:Private Sub TabPage1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage1.Enter str = End Sub3、设置每个可以输入条件的文本框:Private Sub TextBox1_TextChanged(
22、ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If str = Then str = 客户id like & TextBox1.Text & % Else str = str & and 客户id like & TextBox1.Text & % End IfPrivate Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tex
23、tBox2.TextChanged If str = Then str = 公司名 like & TextBox2.Text & % Else str = str & and 公司名 like & TextBox2.Text & % End If Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged If str = Then str = 地址 like & TextBox3.Text & % Else s
24、tr = str & and 地址 like & TextBox3.Text & % End IfPrivate Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged If str = Then str = 城市 like & TextBox4.Text & % Else str = str & and 城市 like & TextBox4.Text & % End If Private Sub TextBox5_Text
25、Changed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged If str = Then str = 区域 like & TextBox5.Text & % Else str = str & and 区域 like & TextBox5.Text & % End If Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handle
26、s TextBox6.TextChanged If str = Then str = 国家 like & TextBox6.Text & % Else str = str & and 国家 like & TextBox6.Text & % End If Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged If str = Then str = 邮编 like & TextBox7.Text & % Els
27、e str = str & and 邮编 like & TextBox7.Text & % End If Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged If str = Then str = 电话 like & TextBox8.Text & % Else str = str & and 电话 like & TextBox8.Text & % End If Private Sub TextBox9_
28、TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.TextChanged If str = Then str = 传真 like & TextBox9.Text & % Else str = str & and 传真 like & TextBox9.Text & % End If Private Sub TextBox10_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) H
29、andles TextBox10.TextChanged If str = Then str = 联系人 like & TextBox10.Text & % Else str = str & and 联系人 like & TextBox10.Text & % End IfPrivate Sub TextBox11_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox11.TextChanged If str = Then str = 联系人职务 like & TextBox11.Text & % Else str = str & and 联系人职务 like & TextBox11.Text & % End If4、查询按钮代码:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e A
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2