ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:124.97KB ,
资源ID:3739440      下载积分:2 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3739440.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Internet应用开发实验报告.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Internet应用开发实验报告.docx

1、Internet应用开发实验报告Internet 应用开发实验报告学 号:XXX姓 名:XXX指导老师:XXX目录一、报告题目 - 2 -二、实验目标 - 2 -三、前期准备 - 2 -a) 、ASP.NET网站创建 - 2 -b)、数据库设计 - 3 -c)、Web界面设计 - 4 -四、三步曲 - 6 -a)、第一步ADO.NET之基本数据操作 - 6 -b)、第二步数据操作封装 - 9 -c)、第三步三层架构设计及实现 - 13 -一、报告题目ASP.NET数据操作三步曲新闻发布系统的设计开发二、实验目标1、 创建ASP.NET网站开发环境;2、 设计一个具有基本样式的Web界面;3、

2、创建一个简单的数据库,其中包含至少一张5个字段以上的表;4、 分别采用三种数据库操作方式,进行对网站进行开发;5、 用户体验的设计实现;三、 前期准备a) 、ASP.NET网站创建打开visual studio 2010 ,新建项目中选择其他项目,选择visual studio 2010 空白解决方案,在方案下新建ASP.NET Web应用程序,如下:b)、数据库设计1、新闻信息表的设计:2、用户信息表的设计:3、数据库代码实现:use mastergo/*-建库-*/if exists(select * from sysdatabases where name=testDB) drop da

3、tabase testDBgo-创建数据库testDBcreate database testDB/*-建表-*/use testDBgo-判断表是否存在if exists(select * from sysobjects where name=UserInfo) drop table UserInfogo-用户信息表create table userInfo ( userID int identity(1,1) primary key, Name varchar(20)not null, Age int not null, Sex char(1),-0 男,女 Email varchar(2

4、0), Pwd varchar(10),)go-判断表是否存在if exists(select * from sysobjects where name=news) drop table newsgo-新闻表create table news( nID int identity(1,1)primary key, nTitle varchar(50)not null, nContent text not null, nTime datetime,)/*存储过程*/-用户登陆create proc proc_login name char(19), pwd char(6)as if not exi

5、sts(select * from UserInfo where Name=name) begin raiserror(用户不存在,16,1) return end if not exists(select * from UserInfo where Name=name and Pwd = pwd) begin raiserror(密码错误,16,1) return endc)、Web界面设计1、登陆界面设计:2、主界面设计:3、点击编辑按钮,进行新闻编辑:4、 输入新闻内容,点击添加新闻:5、点击删除按钮,删除新闻内容:四、三步曲a)、第一步ADO.NET之基本数据操作private sta

6、tic string strConn = Data Source=.;Initial Catalog=testDB;Integrated Security=true; protected void Page_Load(object sender, EventArgs e) public static SqlConnection GetConn() return new SqlConnection(strConn); protected void btnLogin_Click(object sender, EventArgs e) string name1 = txtName.Text.Trim

7、(); string pwd1 = txtPwd.Text.Trim(); string sql = select * from UserInfo where Name= + name1 + and Pwd= + pwd1 + ; bool flag; SqlConnection conn = GetConn(); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); SqlDataReader dr = comm.ExecuteReader(); flag = dr.Read(); if (flag) SessionuserNam

8、e = name1; Response.Redirect(WebSite/Default.aspx); else ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(登陆失败!);); private static string strConn = Data Source=.;Initial Catalog=testDB;Integrated Security=true; public static SqlConnection GetConn() return new SqlConnection(strConn)

9、; protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) BindDataNews(); protected void BindDataNews() string sql = select * from news; SqlConnection conn = GetConn(); conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adapter.Fill(ds); co

10、nn.Close(); DataTable dt = new DataTable(); dt.Columns.Add(nID, typeof(int); dt.Columns.Add(nTitle, typeof(string); dt.Columns.Add(nContent, typeof(string); dt.Columns.Add(nTime, typeof(DateTime); foreach (DataRow Rtest in ds.Tables0.Rows) DataRow dr = dt.NewRow(); drnID = RtestnID.ToString(); drnTi

11、tle = RtestnTitle.ToString().Substring(0, 3) + .; drnContent = RtestnContent.ToString() + ; drnTime = RtestnTime.ToString(); dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); protected void btnEdit_Click(object sender, EventArgs e) Button edit = sender as Button; SessionnID = int.Par

12、se(edit.CommandArgument.ToString(); string sql = string.Format(select nTitle,nContent,nTime from news where nID=0, SessionnID.ToString(); SqlConnection conn = GetConn(); conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adapter.Fill(ds); conn.Close(); D

13、ataTable dt = ds.Tables0; EditTitle.Text = dt.Rows0nTitle.ToString(); EditContent.Text = dt.Rows0nContent.ToString(); protected void btnDel_Click(object sender, EventArgs e) Button delete = sender as Button; int id = int.Parse(delete.CommandArgument.ToString(); string sql = string.Format(delete from

14、 news where nID=0, id); int j; SqlConnection conn = GetConn(); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); j = comm.ExecuteNonQuery(); conn.Close(); if (j 0) ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(删除成功!);); BindDataNews(); else ClientScript.RegisterClientScr

15、iptBlock(this.GetType(), msfg, alert(删除失败!);); protected void btnAdd_Click(object sender, EventArgs e) string title = txtTitle.Text.Trim(); string content = txtContent.Text.Trim(); string sql = string.Format(insert into news values(0,1,2), title, content, DateTime.Now); int j; SqlConnection conn = G

16、etConn(); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); j = comm.ExecuteNonQuery(); conn.Close(); if (j 0) ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(添加成功!);); BindDataNews(); b)、第二步数据操作封装private static string strConn = Data Source=.;Initial Catalog=testDB;Integra

17、ted Security=true; public DBHelper() public static SqlConnection GetConn() return new SqlConnection(strConn); public static bool IfExist(string sql) bool flag; SqlConnection conn = GetConn(); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); SqlDataReader dr = comm.ExecuteReader(); flag = dr

18、.Read(); return flag; public static int ExecuteSql(string sql) int i; SqlConnection conn = GetConn(); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); i = comm.ExecuteNonQuery(); conn.Close(); return i; public static DataSet GetDataSet(string querySql) SqlConnection conn = GetConn(); conn.O

19、pen(); SqlDataAdapter adapter = new SqlDataAdapter(querySql, conn); DataSet ds = new DataSet(); adapter.Fill(ds); conn.Close(); return ds;protected void btnLogin_Click(object sender, EventArgs e) string name1 = txtName.Text.Trim(); string pwd1 = txtPwd.Text.Trim(); string sql = select * from UserInf

20、o where uName= + name1 + and Pwd= + pwd1 + ; if (DBHelper.IfExist(sql) SessionuserName = name1; Response.Redirect(WebSite/Default.aspx); else ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(登陆失败!);); protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) BindDataNew

21、s(); protected void BindDataNews() string sql = select * from news; DataSet ds = DBHelper.GetDataSet(sql); DataTable dt = new DataTable(); dt.Columns.Add(nID, typeof(int); dt.Columns.Add(nTitle, typeof(string); dt.Columns.Add(nContent, typeof(string); dt.Columns.Add(nTime, typeof(DateTime); foreach

22、(DataRow Rtest in ds.Tables0.Rows) DataRow dr = dt.NewRow(); drnID = RtestnID.ToString(); drnTitle = RtestnTitle.ToString().Substring(0, 3) + .; if (RtestnContent.ToString().Length 25) drnContent = RtestnContent.ToString().Substring(0, 24) + .; else drnContent = RtestnContent.ToString() + ; drnTime

23、= RtestnTime.ToString(); dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); protected void btnEdit_Click(object sender, EventArgs e) Button edit = sender as Button; string sql = string.Format(select nTitle,nContent,nTime from news where nID=0, SessionnID.ToString(); DataTable dt = DBH

24、elper.GetDataSet(sql).Tables0; EditTitle.Text = dt.Rows0nTitle.ToString(); EditContent.Text = dt.Rows0nContent.ToString(); protected void btnDel_Click(object sender, EventArgs e) Button delete = sender as Button; int id = int.Parse(delete.CommandArgument.ToString(); string sql = string.Format(delete

25、 from news where nID=0, id); if (DBHelper.ExecuteSql(sql) 0) ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(删除成功!);); BindDataNews(); else ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(删除失败!);); protected void btnAdd_Click(object sender, EventArgs e) string t

26、itle = txtTitle.Text.Trim(); string content = txtContent.Text.Trim(); string sql = string.Format(insert into news values(0,1,2), title, content, DateTime.Now); if (DBHelper.ExecuteSql(sql) 0) ClientScript.RegisterClientScriptBlock(this.GetType(), msfg, alert(添加成功!);); BindDataNews(); c)、第三步三层架构设计及实现

27、如图建立三层架构:DAL层,对数据库的操作:public class News public DataTable GetAllNews() string sql = select * from news; return SQLHelper.Helper.Exec(sql); public DataTable Query(string sql) return SQLHelper.Helper.Exec(sql); public bool Delete(int id) string sql = string.Format(delete from news where nID=0, id); return SQLHelper.Helper.ExecNonQuery(sql)0?true:false; public bool Insert(string sql) return SQLHelper.Helper.ExecNonQuery(sql)0?true:false; SQLHelper数据库帮助类: / / 执行SQL语句,返回影响的记录数 / / SQL语句 / 影响的记录数

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1