收藏 分销(赏)

实验9---图书后台管理模块设计.doc

上传人:精**** 文档编号:2578626 上传时间:2024-06-01 格式:DOC 页数:11 大小:369.54KB 下载积分:8 金币
下载 相关 举报
实验9---图书后台管理模块设计.doc_第1页
第1页 / 共11页
实验9---图书后台管理模块设计.doc_第2页
第2页 / 共11页


点击查看更多>>
资源描述
实验9 图书后台管理模块设计 ———————————————————————————————— 作者: ———————————————————————————————— 日期: 11 个人收集整理 勿做商业用途 实验9 图书后台管理模块设计 9。1实验目的 1、回顾前面学过的控件的应用方法 2、掌握图书信息的新增、修改和删除方法 9.2实验内容 1、通过本实验加强已学控件的应用方法 2、练习实现图书信息新增、修改、删除功能 3、练习图书后台管理模块的设计方法 9.3实验步骤 9。3。1控件设置 在窗体上放置一个HyperLink用来添加图书信息,GridView展示信息. 图6-1 功能设计图 黑色部位为修改部分 图6—2 HyperLink添加链接网页 选择gridview控件,选中编辑列 图6-3 编辑gridview列 设置绑定列 图6-4 绑定列 图6—5 设置gridview要显示的按钮及显示名称 设置数据关键字DataKeyNames为id(主键索引) 图6—6 设置主键索引 9.3.2数据浏览代码编写 Dim conn As OleDbConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load conn = New OleDbConnection("Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=tuanshuguanli;Data Source=.") If Not IsPostBack Then DataBinds() End If End Sub '数据绑定自定义的事件 Sub DataBinds() '建立Command对象 Dim cmd As New OleDbCommand("select * from bookinfo”, conn) ’建立DataAdapter对象 Dim adp As New OleDbDataAdapter(cmd) ’建立DataSet对象 Dim ds As New DataSet() ’填充DataSet对象 adp。Fill(ds, ”link”) ds.Tables("link").DefaultView。Sort = sortString ’绑定数据对象 GridView1。DataSource = ds。Tables("link”)。DefaultView '指定数据源 GridView1。DataBind() '执行绑定 End Sub 图6—7 运行结果 9.3.3添加信息代码编写 在添加信息页面上添加如下控件,为简化都是TextBox 图6-8 信息添加控件设置 编写提交按钮代码: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System。EventArgs) Handles Button1.Click Dim conn As OleDbConnection = New OleDbConnection(”Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=tuanshuguanli;Data Source=.”) Dim strSql As String strSql = ”insert into bookinfo(Title,Author,Company,ISBN,Price) values('" + Title。Text。Trim + "',’" + Author。Text + "','" + Company。Text + "’,’” + ISBN。Text + ”’,’" + Price.Text + "')” Dim cmd As OleDbCommand = New OleDbCommand(strSql, conn) conn.Open() If cmd.ExecuteNonQuery() Then Response.Write(”成功”) Else Response.Write(”失败”) End If conn。Close() End Sub 9.3.4修改、删除、更新代码编写 添加RowEditing 事件 Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI。WebControls。GridViewEditEventArgs) Handles GridView1.RowEditing GridView1。EditIndex = e.NewEditIndex DataBinds() End Sub 添加RowUpdating 事件 Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System。Web。UI。WebControls。GridViewUpdateEventArgs) Handles GridView1.RowUpdating Dim strTitle, strauthor, strcompany, strISBN, strprice As String strTitle = CType(GridView1.Rows(e。RowIndex).Cells(1).Controls(0), TextBox).Text。ToString().Trim() strauthor = CType(GridView1.Rows(e。RowIndex)。Cells(2)。Controls(0), TextBox).Text。ToString().Trim() strcompany = CType(GridView1.Rows(e.RowIndex)。Cells(3).Controls(0), TextBox).Text。ToString().Trim() strISBN = CType(GridView1.Rows(e.RowIndex)。Cells(4).Controls(0), TextBox)。Text.ToString().Trim() strprice = CType(GridView1。Rows(e。RowIndex).Cells(5).Controls(0), TextBox)。Text.ToString().Trim() Dim strSql As String strSql = ”update bookinfo set title='" + strTitle + "',author='" + strauthor + "’,company=’" + strcompany + "’,ISBN=’” + strISBN + "’,price=’" + strprice + ”'" strSql += " where id='" + GridView1.DataKeys(e。RowIndex).Value.ToString() + ”’" conn。Open() ’建立Command对象 Dim cmd As New OleDbCommand(strSql, conn) If cmd。ExecuteNonQuery() Then Response.Write(”修改成功”) Else Response.Write(”修改失败") End If conn.Close() GridView1.EditIndex = -1 DataBinds() End Sub 添加取消编辑RowCancelingEdit 事件 Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System。Web.UI.WebControls。GridViewCancelEditEventArgs) Handles GridView1。RowCancelingEdit GridView1.EditIndex = —1 DataBinds() End Sub 图6-9 编辑事件运行结果 添加删除RowDeleting事件 Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System。Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim strSql As String strSql = "delete from bookinfo" strSql += " where id=’" + GridView1.DataKeys(e。RowIndex)。Value。ToString() + ”’” conn。Open() ’建立Command对象 Dim cmd As New OleDbCommand(strSql, conn) If cmd。ExecuteNonQuery() Then Response。Write("删除成功") Else Response。Write("删除失败”) End If conn。Close() GridView1.EditIndex = —1 DataBinds() End Sub 9。4思考题 1、如何用单独的页面实现修改图书信息的功能? 2、如何使用验证控件对一些信息进行有效性验证?
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服