内蒙古信息工程系学实训报告系部:信息技术系课程名称:网站网页制作专业班级:14计算机网络技术一班姓名:xxx任课老师:xxx实验实训项目名称网站制作实验类型验证型实验室思科网络实验室实验时间[实验方案设计(步骤)]实验目的:1.熟练掌握SQL语句的编写。
2.掌握使用VS2010对网页的设计。
实验步骤:1.登录页面主要代码:protected void Button1_Click(object sender, EventArgs e){string username = TextBox1.Text;string password = TextBox2.Text;string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlCommand cmd = new SqlCommand("select * from UserInfo where username='" + username + "' and password='" + password + "'", conn);conn.Open();SqlDataReader reader = cmd.ExecuteReader();//记?录?集ˉif (reader.Read()){Response.Redirect("main.aspx");}else{Label1.Text = "用?户§名?或ò者?密ü码?错洙?误ó!?!?";}conn.Close();}2.主页面+用户信息管理页面左侧主要运用了TreeView控件,然后用户信息运用了GridView控件,链接数据源,在页面中展示用户信息,主要代码:<asp:GridView ID="GridView1"runat="server"AllowPaging="True"AllowSorting="True"AutoGenerateColumns="False"DataKeyNames="Userid"DataSourceID="SqlDataSource1"style="font-family: 楷?体?; font-size: medium"Width="550px"BackColor="#DEBA84"BorderColor="#DEBA84"BorderStyle="None" BorderWidth="1px"CellPadding="3"CellSpacing="2"><Columns><asp:BoundField DataField="Userid"HeaderText="序ò号?"ReadOnly="True"SortExpression="Userid"/><asp:BoundField DataField="UserName"HeaderText="用?户§名?"SortExpression="UserName"/><asp:BoundField DataField="Password"HeaderText="密ü码?"SortExpression="Password"/><asp:BoundField DataField="Email"HeaderText="电?子哩?邮?件t" SortExpression="Email"/><asp:CommandField ShowDeleteButton="True"ShowEditButton="True"/></Columns><FooterStyle BackColor="#F7DFB5"ForeColor="#8C4510"/><HeaderStyle BackColor="#A55129"Font-Bold="True"ForeColor="White"/><PagerStyle ForeColor="#8C4510"HorizontalAlign="Center"/><RowStyle BackColor="#FFF7E7"ForeColor="#8C4510"/><SelectedRowStyle BackColor="#738A9C"Font-Bold="True"ForeColor="White"/><SortedAscendingCellStyle BackColor="#FFF1D4"/><SortedAscendingHeaderStyle BackColor="#B95C30"/><SortedDescendingCellStyle BackColor="#F1E5CE"/><SortedDescendingHeaderStyle BackColor="#93451F"/></asp:GridView><br/><asp:SqlDataSource ID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:StudentManagerConnectionString %>"DeleteCommand="DELETE FROM [UserInfo] WHERE [Userid] = @Userid"InsertCommand="INSERT INTO [UserInfo] ([Userid], [UserName], [Password], [Email]) VALUES (@Userid, @UserName, @Password, @Email)"SelectCommand="SELECT * FROM [UserInfo]"UpdateCommand="UPDATE [UserInfo] SET [UserName] = @UserName, [Password] = @Password, [Email] = @Email WHERE [Userid] = @Userid">3.学籍信息添加页面主要代码:protected void Button1_Click(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlCommand cmd = new SqlCommand("insert intoStudentXj(Sno,Sname,Ssex,Sbrithday,DepartNo,ClassNo,Tel,Srxtime,xuezhi,xueli,address,youbian ,zzmm,pingjia)values('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + RadioButtonList1.Text + "','" + this.TextBox3.Text + "','" + this.TextBox12.Text + "','" + this.TextBox4.Text + "','" + this.TextBox5.Text + "','" + this.TextBox6.Text + "','" +this.TextBox7.Text + "','" + this.TextBox8.Text + "','" + this.TextBox9.Text + "','" +this.TextBox10.Text + "','" + DropDownList1.Text + "','" + this.TextBox11.Text + "')", conn); conn.Open();cmd.ExecuteNonQuery();conn.Close();}4.学籍信息修改本页面也是用GridView控件,与数据库连接,展示出学籍信息,然后生成“修改”,单击“修改”方可进行修改,主要代码:<asp:GridView ID="GridView1"runat="server"AllowPaging="True"AllowSorting="True"AutoGenerateColumns="False"BackColor="#DEBA84"BorderColor="#DEBA84"BorderStyle="None"BorderWidth="1px"CellPadding="3"CellSpacing="2"DataKeyNames="Sno"DataSourceID="SqlDataSource1"style="text-align: center; font-family: 楷?体?; font-size: large; margin-top: 0px;"Width="1471px"><Columns><asp:BoundField DataField="Sno"HeaderText="Sno"ReadOnly="True"SortExpression="Sno"/><asp:BoundField DataField="Sname"HeaderText="Sname"SortExpression="Sname"/><asp:BoundField DataField="Ssex"HeaderText="Ssex"SortExpression="Ssex"/><asp:BoundField DataField="Sbrithday"HeaderText="Sbrithday"本页面运用GridView控件展示出学生信息,设置三种条件查询,按学号、姓名、系别方可查询出学生信息,主要代码:protected void Page_Load(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlDataAdapter da = new SqlDataAdapter("select * from StudentXj", conn);DataSet ds = new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();}protected void Button1_Click(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlDataAdapter da = new SqlDataAdapter("select * from StudentXj where Sno='" +this.TextBox1.Text + "' or Sname='"+ this.TextBox2.Text + "' or DepartNo='"+ this.TextBox3.Text + "'", conn);DataSet ds = new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();}6.课程信息添加主要代码:protected void Button1_Click(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlCommand cmd = new SqlCommand("insert intoCourse(Courseid,CourseName,Credit,Datetime)values('" + this.TextBox1.Text + "','" +this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.TextBox4.Text + "')", conn); conn.Open();cmd.ExecuteNonQuery();conn.Close();Label1.Text = "添?加ó成é功|!?!?!?";}7.课程信息修改添加了GridView控件,使它与数据源连接,查询课程信息分三个条件,按课程编号、课程名称、日期方可查询,主要代码:protected void Page_Load(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlDataAdapter da = new SqlDataAdapter("select * from Course", conn);DataSet ds = new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();}protected void Button1_Click(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlDataAdapter da = new SqlDataAdapter("select * from Course where Courseid='" + this.TextBox1.Text + "' or CourseName='" + this.TextBox2.Text + "' or Datetime='" +this.TextBox3.Text + "'", conn);DataSet ds = new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();}9.课程信息删除主要代码:<asp:GridView ID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"BackColor="#DEBA84"BorderColor="#DEBA84"BorderStyle="None"BorderWidth="1px"CellPadding="3"CellSpacing="2"DataKeyNames="Courseid"DataSourceID="SqlDataSource1"style="text-align: center; font-family: 楷?体?; font-size: large;"><Columns><asp:BoundField DataField="Courseid"HeaderText="Courseid"ReadOnly="True"SortExpression="Courseid"/><asp:BoundField DataField="CourseName"HeaderText="CourseName"SortExpression="CourseName"/><asp:BoundField DataField="Credit"HeaderText="Credit"SortExpression="Credit"/><asp:BoundField DataField="Datetime"HeaderText="Datetime"SortExpression="Datetime"/><asp:CommandField ShowDeleteButton="True"/></Columns><FooterStyle BackColor="#F7DFB5"ForeColor="#8C4510"/><HeaderStyle BackColor="#A55129"Font-Bold="True"ForeColor="White"/><PagerStyle ForeColor="#8C4510"HorizontalAlign="Center"/><RowStyle BackColor="#FFF7E7"ForeColor="#8C4510"/><SelectedRowStyle BackColor="#738A9C"Font-Bold="True"ForeColor="White"/><SortedAscendingCellStyle BackColor="#FFF1D4"/><SortedAscendingHeaderStyle BackColor="#B95C30"/><SortedDescendingCellStyle BackColor="#F1E5CE"/><SortedDescendingHeaderStyle BackColor="#93451F"/></asp:GridView></center><asp:SqlDataSource ID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:StudentManagerConnectionString3 %>"DeleteCommand="DELETE FROM [Course] WHERE [Courseid] = @Courseid"InsertCommand="INSERT INTO [Course] ([Courseid], [CourseName], [Credit],[Datetime]) VALUES (@Courseid, @CourseName, @Credit, @Datetime)"SelectCommand="SELECT * FROM [Course]"UpdateCommand="UPDATE [Course] SET [CourseName] = @CourseName, [Credit] = @Credit, [Datetime] = @Datetime WHERE [Courseid] = @Courseid"><DeleteParameters><asp:Parameter Name="Courseid"Type="Int32"/></DeleteParameters>10.学生成绩添加主要代码:protected void Button1_Click(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlCommand cmd = new SqlCommand("insert intoStudentCJ(Sno,Sname,CourseName,Score)values('" + this.TextBox1.Text + "','" +this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.TextBox4.Text + "')", conn); conn.Open();cmd.ExecuteNonQuery();conn.Close();Label1.Text = "添?加ó成é功|!?!?!?";}11.学生成绩修改主要代码:<asp:GridView ID="GridView1"runat="server"添加了GridView控件,使它与数据源连接,查询课程信息分三个条件,按课程名称、学号、姓名方可查询,主要代码:protected void Page_Load(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlDataAdapter da = new SqlDataAdapter("select * from StudentCJ", conn);DataSet ds = new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();}protected void Button2_Click(object sender, EventArgs e){string connStr = "server=(local);uid=sa;pwd=123456;database=StudentManager";SqlConnection conn = new SqlConnection(connStr);SqlDataAdapter da = new SqlDataAdapter("select * from StudentCJ where CourseName='" + this.TextBox1.Text + "' or Sno='" + this.TextBox2.Text + "' or Sname='" + this.TextBox3.Text + "'", conn);DataSet ds = new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();}13.学生成绩删除主要代码:<asp:GridView ID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"BackColor="#DEBA84"BorderColor="#DEBA84"BorderStyle="None"BorderWidth="1px"CellPadding="3"CellSpacing="2"DataKeyNames="Sno"DataSourceID="SqlDataSource1"style="font-family: 楷?体?; font-size: large; text-align: center"Width="561px"><Columns><asp:BoundField DataField="Sno"HeaderText="Sno"ReadOnly="True"SortExpression="Sno"/><asp:BoundField DataField="Sname"HeaderText="Sname"SortExpression="Sname"/><asp:BoundField DataField="CourseName"HeaderText="CourseName"SortExpression="CourseName"/><asp:BoundField DataField="Score"HeaderText="Score"SortExpression="Score"/><asp:CommandField ShowDeleteButton="True"/></Columns><FooterStyle BackColor="#F7DFB5"ForeColor="#8C4510"/><HeaderStyle BackColor="#A55129"Font-Bold="True"ForeColor="White"/><PagerStyle ForeColor="#8C4510"HorizontalAlign="Center"/><RowStyle BackColor="#FFF7E7"ForeColor="#8C4510"/><SelectedRowStyle BackColor="#738A9C"Font-Bold="True"ForeColor="White"/><SortedAscendingCellStyle BackColor="#FFF1D4"/><SortedAscendingHeaderStyle BackColor="#B95C30"/><SortedDescendingCellStyle BackColor="#F1E5CE"/><SortedDescendingHeaderStyle BackColor="#93451F"/></asp:GridView><asp:SqlDataSource ID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:StudentManagerConnectionString6 %>"DeleteCommand="DELETE FROM [StudentCJ] WHERE [Sno] = @Sno"InsertCommand="INSERT INTO [StudentCJ] ([Sno], [Sname], [CourseName], [Score]) VALUES (@Sno, @Sname, @CourseName, @Score)"SelectCommand="SELECT * FROM [StudentCJ]"UpdateCommand="UPDATE [StudentCJ] SET [Sname] = @Sname, [CourseName] = @CourseName, [Score] = @Score WHERE [Sno] = @Sno"><DeleteParameters><asp:Parameter Name="Sno"Type="String"/></DeleteParameters>。