文档详情

实验六 .NE Web程序开发技术.doc

发布:2016-09-24约2.17万字共5页下载文档
文本预览下载声明
实 验 报 告 课程名称 Web开发技术及其应用 实验名称 实验六 .NET Web程序开发技术 姓 名__ _ _ ___学 号____ 专业班级_ 实验日期__ 年_ _月_ _日 成绩_____ __ 指导教师___ __ __ 一、实验目的 1.了解ASP.NET的运行模式。 2.掌握C#或VB.NET语言编程技术。 3.掌握ASP.NET的基本控件的使用。 4.熟悉ASP.NET的服务器对象。 5.掌握ADO.NET数据库访问技术。 二、实验环境 硬件: PC机,要求有Internet网络环境。 软件: Windows2003Server、Windows XP、Win7操作系统。 VS2005开发环境。 三、实验内容与步骤 (一)实验内容:开发一个简单的用户注册登录系统。 (二)实验步骤: 1.在sqlserver中建立一个数据库名为student;并添加几条数据记录,以便后续链接使用; 2.在VS2005中新建网站,在网站中建一个web窗体,命名为“denglu”,在denglu.aspx文件的设计页面设计如图所示的登陆界面,更改各个控件的ID,注意要更改密码框的TextMode为Password,否则密码将以明码的方式显示出来。 3.双击设计界面,进入登陆.aspx.cs文件,为登陆按钮控件编写代码,实现与数据库的链接,如下: protected void Btn_confirm_Click1(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = user id=stud9;data source=9;integrated security=false;initial catalog=student;pwd=stud9;//设置连接字符串 con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = select * from student; SqlDataReader myreader = cmd.ExecuteReader(); string uName = this.txt_name.Text; string uPwd = this.txt_psw.Text; bool isTrue = false; while (myreader.Read()) { if (myreader[name].ToString().Trim() == uName myreader[passwd].ToString().Trim() == uPwd) { isTrue = true; } } if (isTrue == true) { Response.Write(script language=javascriptalert(登录成功!)/script); } else { Response.Write(script language=javascriptalert(用户名不存在或密码不正确!)/script); } } 4.新建一个web窗体,命名为注册,在设计页面内设计如图所示的注册页面,更改各个控件的ID; 5.双击注册按钮,进入注册.aspx.cs文件,为注册事件编写代码如下: protected void Button1_Click1(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = user id=stud9;data source=9;integrated security=false;initial catalog=student;pwd=stud9;//设置连接字符串 con.Open(); SqlCommand cmd = new SqlCommand(); stri
显示全部
相似文档