杭电aspnet期末样卷_第1页
杭电aspnet期末样卷_第2页
杭电aspnet期末样卷_第3页
杭电aspnet期末样卷_第4页
杭电aspnet期末样卷_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、期末样卷一、描述1、 打开VS2010,新建一个空网站项目,命名为“学号姓名”,保存在磁盘考生目录;2、 利用VS2010新建一个本地数据库,命名为“Books.mdf”,保存在项目App_Data目录;或使用已有数据库文件“Books.mdf”;3、 整体目录结构如下图:4、 数据库中包含三张表:UserInfo 用户表UserIDVarchar(10) PK用户IDUserNameVarchar(50)用户名PasswordVarchar(50)密码BookInfo 书目表BookIDVarchar(10) PK书号IDBookNameVarchar(50)书名PriceFloat价格Or

2、derInfo 订单表UserIDVarchar(10) PK用户IDBookIDVarchar(10) PK书号IDCountInt数量5、把压缩包内三篇短文放置在目录Books下。二、试题1、面向对象题(20分)。周三下午1:30 6/312 创建一个抽象类:书类(Book),包含书号BookID、书名BookName,价格Price,包含一个抽象方法int FindWord(string word);创建一个教材类(TeachingMaterial)继承于书类,包含内容Content属性信息;实现FindWord ()方法,要求根据输入参数word在Content中查找出现的次数。2、控

3、件应用题(30分)新建模板页MasterPage.master,模板页含有站点地图信息;并新建一个内容页TestControl.aspx,如下图构建注册页面,使用相对应的验证控件进行输入数据的有效性验证。点击取消按钮清除文本框内已填写数据,点击确定按钮进行提交。3、数据库题(50分)主页面MainPage.aspx主要由一个GridView构成,页面打开时GridView显示Book表中的信息,并允许选择删除一条Book信息(注意如删除书本信息,必须同时考虑删除订单信息)-using System;using System.Collections.Generic;using System.Li

4、nq;using System.Web;/ <summary>/ Student 的摘要说明/ </summary>public class Student:Human /.public Student()/ TODO: 在此处添加构造函数逻辑/ public override void Work() / public void getInfo(params int numbers) foreach (int num in numbers) /if num is Prime ouput num; private bool isPrime(int num) return

5、true; public abstract class Human public int Height get; set; public float Weight get; set; private string _name; public string Name get return _name; set _name = value; public abstract void Work();-<% Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs&qu

6、ot; Inherits="_Default" %><!DOCTYPE html><html xmlns="/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title></head><body&g

7、t; <form id="form1" runat="server"> <div> </div> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Scholl" DataValueField="SchoolId"

8、> </asp:DropDownList> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="StuId" DataSourceID="SqlDataS

9、ource2"> <Columns> <asp:BoundField DataField="StuId" HeaderText="学号" ReadOnly="True" SortExpression="StuId" /> <asp:BoundField DataField="StuName" HeaderText="姓名" SortExpression="StuName" /> <asp:Bound

10、Field DataField="Scholl" HeaderText="学院" SortExpression="Scholl" /> </Columns> </asp:GridView> <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1" DataTextField="Scholl" DataValueFie

11、ld="SchoolId"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT Student.StuId, Student.StuName, School.Scholl FROM Student INNER

12、JOIN School ON Student.SchoolId = School.SchoolId WHERE (Student.SchoolId = SchoolID)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="SchoolID" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSourc

13、e> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand

14、="SELECT * FROM School"></asp:SqlDataSource> </form></body></html>-using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Configuration; protect

15、ed void Page_Load(object sender, EventArgs e) protected void Button1_Click(object sender, EventArgs e) SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings"ConnectionString".ConnectionString); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "

16、;update student set schoolId="+DropDownList2.SelectedValue+" where schoolId="+DropDownList1.SelectedValue; cmd.ExecuteNonQuery(); cmd.CommandText = "select Count(*) from student where SchoolId="+DropDownList2.SelectedValue; Label1.Text = cmd.ExecuteScalar().ToString(); con.C

17、lose(); -using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Configuration; protected void Page_Load(object sender, EventArgs e) protected void Button1_Click(object sender, Event

18、Args e) SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings"ConnectionString".ConnectionString); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "update stuInfo set schoolID="+DropDownList2.SelectedValue+"where schoolID ="+Dr

19、opDownList1.SelectedValue; cmd.ExecuteNonQuery(); cmd.CommandText = "select count(*) from stuInfo where schoolID="+DropDownList2.SelectedValue; Label1.Text = cmd.ExecuteScalar().ToString(); con.Close(); -<% Page Language="C#" AutoEventWireup="true" CodeFile="Def

20、ault.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head runat="server"> <tit

21、le></title></head><body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FR

22、OM Student WHERE StuID = StuID" InsertCommand="INSERT INTO Student (StuID, StuName, SchoolID) VALUES (StuID, StuName, SchoolID)" SelectCommand="SELECT * FROM Student" UpdateCommand="UPDATE Student SET StuName = StuName, SchoolID = SchoolID WHERE StuID = StuID">

23、<DeleteParameters> <asp:Parameter Name="StuID" Type="String" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="StuID" Type="String" /> <asp:Parameter Name="StuName" Type="String" /> <asp:P

24、arameter Name="SchoolID" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="StuName" Type="String" /> <asp:Parameter Name="SchoolID" Type="String" /> <asp:Parameter Name="StuID&qu

25、ot; Type="String" /> </UpdateParameters> </asp:SqlDataSource> <br /> 原先的学院ID为:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> &nbsp; 学院学生数量:<asp:Label ID="Label2" runat="server" Text=&

26、quot;Labe2"></asp:Label> <br /> 选择要更新的学院:<asp:DropDownList ID="DropDownList2" runat="server"> <asp:ListItem Selected="True">计算机学院</asp:ListItem> <asp:ListItem>软件工程学院</asp:ListItem> <asp:ListItem Value="电气学院"

27、></asp:ListItem> </asp:DropDownList> <br /> <asp:Button ID="Button1" runat="server" Text="确定更新" onclick="Button1_Click" /> <br /> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColum

28、ns="False" DataKeyNames="StuID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="StuID" HeaderText="StuID" ReadOnly="True" SortExpression="StuID" /> <asp:BoundField DataField="StuName"

29、; HeaderText="StuName" SortExpression="StuName" /> <asp:BoundField DataField="SchoolID" HeaderText="SchoolID" SortExpression="SchoolID" /> </Columns> </asp:GridView> <br /> </div> </form></body></html&g

30、t;using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data.SqlClient;using System.Data; /建立数据库连接 string str = ConfigurationManager.ConnectionStrings"ConnectionString".Co

31、nnectionString.ToString(); SqlConnection conn; protected void Page_Load(object sender, EventArgs e) conn = new SqlConnection(str); /打开数据库 conn.Open(); /获取原先学院信息 string sql = string.Format("select SchoolID from Student"); /创建查询器 SqlDataAdapter sad = new SqlDataAdapter(sql, conn); /创建结果集 Dat

32、aSet dataSet = new DataSet(); /将结果集填入 sad.Fill(dataSet); Label1.Text = dataSet.Tables0.Rows0"SchoolID".ToString(); Label2.Text = dataSet.Tables0.Rows.Count.ToString(); conn.Close(); protected void Button1_Click(object sender, EventArgs e) conn = new SqlConnection(str); /打开数据库 conn.Open();

33、/更新数据库 /建立数据库命令 SqlCommand sqlcommd2 = new SqlCommand("update Student set SchoolID=" + (DropDownList2.SelectedIndex + 1) + " where SchoolID=" + Label1.Text.ToString(), conn); /判断是否命令执行成功 if (sqlcommd2.ExecuteNonQuery() > 0) Response.Write("更新成功!"); GridView1.DataBind

34、(); conn.Close(); using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data.SqlClient;using System.Data; /获取连接字符串 string str = ConfigurationManager.ConnectionStrings"Connectio

35、nString".ConnectionString.ToString(); SqlConnection conn; protected void Page_Load(object sender, EventArgs e) conn = new SqlConnection(str); /打开数据库 conn.Open(); /获取原先学院信息 string sql = string.Format("select * from Student"); /创建查询器 SqlDataAdapter sad = new SqlDataAdapter(sql, conn); /

36、创建结果集 DataSet dataSet = new DataSet(); /将结果集填入 sad.Fill(dataSet); Label1.Text = dataSet.Tables0.Rows0"SchoolID".ToString(); Label2.Text = dataSet.Tables0.Rows.Count.ToString(); /使用sqlcommd1.ExecuteScalar()进行count SqlCommand sqlcommd1 = new SqlCommand("select count(*) from Student"

37、;, conn); Label3.Text = sqlcommd1.ExecuteScalar().ToString(); /使用sqlcommd1.ExecuteReader() SqlCommand sqlcommd2 = new SqlCommand("select StuName from Student where SchoolID = 2", conn); SqlDataReader reader = sqlcommd2.ExecuteReader(); string str_name = "?" while(reader.Read() st

38、r_name += reader0 + "," Session"name_1" = str_name; conn.Close(); protected void Button1_Click(object sender, EventArgs e) conn = new SqlConnection(str); /打开数据库 conn.Open(); /更新数据库 /建立数据库命令 SqlCommand sqlcommd2 = new SqlCommand("update Student set SchoolID=" + (DropDown

39、List2.SelectedIndex + 1) + " where SchoolID=" + Label1.Text.ToString(), conn);/ SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)" ,conn);/ SqlCommand sqlcommd2 = new SqlCommand("delete from Student where St

40、uName = 'HHHH'" ,conn); /判断是否命令执行成功 if (sqlcommd2.ExecuteNonQuery() > 0) Response.Write("更新成功!"); GridView1.DataBind(); conn.Close(); protected void Button2_Click(object sender, EventArgs e) Response.Redirect("check.aspx"); protected void Button3_Click(object send

41、er, EventArgs e) /打开数据库 conn = new SqlConnection(str); conn.Open(); SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)", conn); /判断是否命令执行成功 if (sqlcommd2.ExecuteNonQuery() > 0) Response.Write("更新成功!"); GridView

42、1.DataBind(); conn.Close(); protected void Button4_Click(object sender, EventArgs e) /打开数据库 conn = new SqlConnection(str); conn.Open(); SqlCommand sqlcommd2 = new SqlCommand("delete from Student where StuName = '张三'", conn); /判断是否命令执行成功 if (sqlcommd2.ExecuteNonQuery() > 0) Respo

43、nse.Write("更新成功!"); GridView1.DataBind(); conn.Close(); protected void Button5_Click(object sender, EventArgs e) if (FileUpload1.HasFile) FileUpload1.SaveAs(Server.MapPath("/uploadFiles/") + FileUpload1.FileName); Image1.ImageUrl = "/uploadFiles/" + FileUpload1.FileName

44、; Label4.Text = "上传成功!" -后台代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data.SqlClient;using System.Data; /获取连接字符串 string str = ConfigurationManager.Connection

45、Strings"ConnectionString".ConnectionString.ToString(); SqlConnection conn; protected void Page_Load(object sender, EventArgs e) conn = new SqlConnection(str); /打开数据库 conn.Open(); /获取原先学院信息 string sql = string.Format("select * from Student"); /创建查询器 SqlDataAdapter sad = new SqlDat

46、aAdapter(sql, conn); /创建结果集 DataSet dataSet = new DataSet(); /将结果集填入 sad.Fill(dataSet); Label1.Text = dataSet.Tables0.Rows0"SchoolID".ToString(); Label2.Text = dataSet.Tables0.Rows.Count.ToString(); /使用sqlcommd1.ExecuteScalar()进行count SqlCommand sqlcommd1 = new SqlCommand("select coun

47、t(*) from Student", conn); Label3.Text = sqlcommd1.ExecuteScalar().ToString(); /使用sqlcommd1.ExecuteReader() SqlCommand sqlcommd2 = new SqlCommand("select StuName from Student where SchoolID = 2", conn); SqlDataReader reader = sqlcommd2.ExecuteReader(); string str_name = "?"

48、while(reader.Read() str_name += reader0 + "," Session"name_1" = str_name; conn.Close(); protected void Button1_Click(object sender, EventArgs e) conn = new SqlConnection(str); /打开数据库 conn.Open(); /更新数据库 /建立数据库命令 SqlCommand sqlcommd2 = new SqlCommand("update Student set Schoo

49、lID=" + (DropDownList2.SelectedIndex + 1) + " where SchoolID=" + Label1.Text.ToString(), conn);/ SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)" ,conn);/ SqlCommand sqlcommd2 = new SqlCommand("delete from Student where StuName = 'HHHH'" ,conn); /判断是否命令执行成功 if (sqlcommd2.ExecuteNonQuery() > 0) Response.Write("更新成功!"); GridView1.DataBind()

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论