数据库

  1. use master
  2. if exists (select * from sysdatabases where name='bond')
  3. drop database bond
  4. create database bond
  5. on PRIMARY
  6. (
  7. name='bond_data',
  8. FILENAME='F:\asp\理财代销\management\bond.mdf',
  9. filegrowth=20%,
  10. size=10MB
  11. )
  12. LOG ON
  13. (
  14. name='bond_log',
  15. FILENAME='F:\asp\理财代销\management\bond_log.ldf',
  16. size=3MB,
  17. MAXSIZE=20MB
  18. )
  19.  
  20. use bond
  21. --基金类型表(左用)
  22. if exists (select * from sys.objects where name='jjlx')
  23. drop table jjlx
  24. create table jjlx
  25. (
  26. id int primary key identity(1,1), --id
  27. jjlx varchar(50) not null --基金类型
  28. )
  29.  
  30. --基金类型表增加存储过程
  31. if exists(select * from sys.objects where name='jjlx_add')
  32. drop procedure jjlx_add
  33. go
  34. create proc jjlx_add
  35. @jjlx varchar(50)
  36. as
  37. insert into jjlx values (@jjlx)
  38. go
  39. --基金类型表查询存储过程
  40. if exists(select * from sys.objects where name='p_jjlx')
  41. drop procedure p_jjlx
  42. go
  43. create proc p_jjlx
  44. as
  45. select * from jjlx
  46. go
  47. --基金类型表修改存储过程
  48. if exists(select * from sys.objects where name='jjlx_gai')
  49. drop procedure jjlx_gai
  50. go
  51. create proc jjlx_gai
  52. @id int,
  53. @jjlx varchar(50)
  54. as
  55. UPDATE jjlx SET jjlx=@jjlx where id=@id
  56. go
  57. --基金类型表删除存储过程
  58. if exists(select * from sys.objects where name='jjlx_delete')
  59. drop procedure jjlx_delete
  60. go
  61. create proc jjlx_delete
  62. @id int,
  63. @jjlx varchar(50)
  64. as
  65. delete from jjlx where id=@id and jjlx=@jjlx
  66. go

链接数据库
Web.config

  1. <connectionStrings>
  2. <add name="conn" connectionString="server=.;database=bond;integrated security=true" />
  3. </connectionStrings>

Model层
managementModel类

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace managementModel
  8. {
  9. public class jjlxs//基金类型表
  10. {
  11. public int id { set; get; }//id
  12. public string jjlx { set; get; } //基金类型
  13.  
  14. }
  15. }

DAL层
添加引用 Model层
添加程序集引用 using System.Configuration;
managementDAL类

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. using managementModel;
  9. namespace managementDAL
  10. {
  11. public class jjlxdal
  12. {
  13. DBHelper db = new DBHelper();
  14. /// <summary>
  15. /// 查询基金类型
  16. /// </summary>
  17. /// <returns></returns>
  18. public DataSet Searchjjlx()
  19. {
  20. string sql = "p_jjlx";
  21. return db.Search(sql);
  22. }
  23. /// <summary>
  24. /// 增加基金类型
  25. /// </summary>
  26. /// <param name="stu"></param>
  27. /// <returns></returns>
  28. public int Insertjjlx(jjlxs stujjlx)
  29. {
  30. string sql = "jjlx_add";
  31. SqlParameter[] para ={
  32. new SqlParameter("@jjlx",stujjlx.jjlx)
  33. };
  34. return db.IUD(sql, para);
  35. }
  36. /// <summary>
  37. /// 修改基金类型
  38. /// </summary>
  39. /// <param name="stu"></param>
  40. /// <returns></returns>
  41. public int Udatejjlx(jjlxs stujjlx)
  42. {
  43. string sql = "jjlx_gai";
  44. SqlParameter[] para ={
  45. new SqlParameter("@id",stujjlx.id),
  46. new SqlParameter("@jjlx",stujjlx.jjlx)
  47. };
  48. return db.IUD(sql, para);
  49. }
  50. /// <summary>
  51. /// 删除基金类型
  52. /// </summary>
  53. /// <param name="stu"></param>
  54. /// <returns></returns>
  55. public int Deletejjlx(jjlxs stujjlx)
  56. {
  57. string sql = "jjlx_delete";
  58. SqlParameter[] para ={
  59. new SqlParameter("@id",stujjlx.id),
  60. new SqlParameter("@jjlx",stujjlx.jjlx)
  61. };
  62. return db.IUD(sql, para);
  63. }
  64. }
  65. }

DBHelper类

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9. namespace managementDAL
  10. {
  11. public class DBHelper
  12. {
  13. public static string conn = ConfigurationManager.ConnectionStrings["conn"].ToString();
  14. /// <summary>
  15. /// 增删改的方法
  16. /// </summary>
  17. /// <param name="sql">增删改的存储过程</param>
  18. /// <param name="param">存储过程使用的参数</param>
  19. /// <returns></returns>
  20. public int IUD(string sql, SqlParameter[] param)
  21. {
  22. int count = ;
  23. SqlConnection con = new SqlConnection(conn);
  24. con.Open();
  25. SqlCommand com = new SqlCommand(sql, con);
  26. com.CommandType = CommandType.StoredProcedure;
  27. com.Parameters.AddRange(param);
  28. count = com.ExecuteNonQuery();
  29. con.Close();
  30. return count;
  31. }
  32. /// <summary>
  33. /// 查询返回DATASET
  34. /// </summary>
  35. /// <param name="sql"></param>
  36. /// <returns></returns>
  37. public DataSet Search(string sql)
  38. {
  39. DataSet ds = new DataSet();
  40. SqlConnection con = new SqlConnection(conn);
  41. SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
  42. adapter.Fill(ds);
  43. return ds;
  44. }
  45.  
  46. }
  47. }

BLL层
添加引用 Model层
添加引用 DAL层

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using managementDAL;
  7. using managementModel;
  8. using System.Data;
  9. namespace managementBLL
  10. {
  11. public class jjlxbll
  12. {
  13. jjlxdal dal = new jjlxdal();
  14. /// <summary>
  15. /// 查询基金类型
  16. /// </summary>
  17. /// <returns></returns>
  18. public DataSet Searchjjlx() {
  19. return dal.Searchjjlx();
  20. }
  21. /// <summary>
  22. /// 增加基金类型
  23. /// </summary>
  24. /// <param name="stu"></param>
  25. /// <returns></returns>
  26. public bool Insertjjlx(jjlxs stujjlx)
  27. {
  28. bool flag = false;
  29. if (stujjlx.jjlx.Length != )
  30. {
  31. int count = dal.Insertjjlx(stujjlx);
  32. if (count > )
  33. {
  34. flag = true;
  35. }
  36. }
  37. return flag;
  38. }
  39. /// <summary>
  40. /// 修改基金类型
  41. /// </summary>
  42. /// <param name="stujjlx"></param>
  43. /// <returns></returns>
  44. public bool Udatejjlx(jjlxs stujjlx)
  45. {
  46. bool flag = false;
  47. if (stujjlx.jjlx.Length != &&stujjlx.id!=)
  48. {
  49. int count = dal.Udatejjlx(stujjlx);
  50. if (count > )
  51. {
  52. flag = true;
  53. }
  54. }
  55. return flag;
  56. }
  57. /// <summary>
  58. /// 删除基金类型
  59. /// </summary>
  60. /// <param name="stujjlx"></param>
  61. /// <returns></returns>
  62. public bool Deletejjlx(jjlxs stujjlx)
  63. {
  64. bool flag = false;
  65. if (stujjlx.jjlx.Length != && stujjlx.id != )
  66. {
  67. int count = dal.Deletejjlx(stujjlx);
  68. if (count > )
  69. {
  70. flag = true;
  71. }
  72. }
  73. return flag;
  74. }
  75. }
  76. }

UI 层
添加引用 Model层
添加引用 BLL层
基金类型.aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="基金类型表.aspx.cs" Inherits="management.index" %>
  2.  
  3. <!DOCTYPE html>
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  8. <title></title>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <asp:Label ID="Label2" runat="server" Text="类型id:"></asp:Label>
  13. &nbsp;
  14. <asp:TextBox ID="txtid" runat="server"></asp:TextBox>
  15. <div>
  16.  
  17. </div>
  18. <asp:Label ID="Label1" runat="server" Text="基金类型:"></asp:Label>
  19. <asp:TextBox ID="txtjjlx" runat="server"></asp:TextBox>
  20. <br />
  21. <br />
  22. <asp:Button ID="btnadd" runat="server" OnClick="btnadd_Click" Text="增加" />
  23. <asp:Button ID="btndelete" runat="server" OnClick="btndelete_Click" Text="删除" />
  24. <asp:Button ID="btngai" runat="server" OnClick="btngai_Click" Text="修改" />
  25. <br />
  26. <table border="">
  27. <tr><th>类型id</th><th>基金类型</th></tr>
  28. <asp:Repeater ID="repjjlx" runat="server">
  29. <ItemTemplate>
  30. <tr>
  31. <td><%#Eval("id") %></td>
  32. <td><%#Eval ("jjlx") %></td>
  33. </tr>
  34. </ItemTemplate>
  35. </asp:Repeater>
  36. </table>
  37. </form>
  38. </body>
  39. </html>

基金类型.aspx.cs
基金类型.aspx.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using managementBLL;
  8. using System.Data;
  9. using managementModel;
  10. namespace management
  11. {
  12. public partial class index : System.Web.UI.Page
  13. {
  14. jjlxbll bll = new jjlxbll();
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. Bind();
  18. }
  19. public void Bind() {
  20.  
  21. this.repjjlx.DataSource = bll.Searchjjlx().Tables[];
  22. this.repjjlx.DataBind();
  23. }
  24. protected void btnadd_Click(object sender, EventArgs e)
  25. {
  26. jjlxs stujjlx = new jjlxs {jjlx=txtjjlx.Text };
  27. if (bll.Insertjjlx(stujjlx))
  28. {
  29. Bind();
  30. Response.Write("<script>alert('增加成功!')</script>");
  31. }
  32. else {
  33. Response.Write("<script>alert('增加失败!')</script>");
  34. }
  35. }
  36.  
  37. protected void btndelete_Click(object sender, EventArgs e)
  38. {
  39. jjlxs stujjlx = new jjlxs();
  40. stujjlx.id = Convert.ToInt32(txtid.Text);
  41. stujjlx.jjlx = txtjjlx.Text;
  42. if (bll.Deletejjlx(stujjlx))
  43. {
  44. Bind();
  45. Response.Write("<script>alert('删除成功!')</script>");
  46. }
  47. else
  48. {
  49. Response.Write("<script>alert('删除失败!')</script>");
  50. }
  51. }
  52.  
  53. protected void btngai_Click(object sender, EventArgs e)
  54. {
  55. jjlxs stujjlx = new jjlxs();
  56. stujjlx.id = Convert.ToInt32(txtid.Text);
  57. stujjlx.jjlx = txtjjlx.Text;
  58. if (bll.Udatejjlx(stujjlx))
  59. {
  60. Bind();
  61. Response.Write("<script>alert('修改成功!')</script>");
  62. }
  63. else
  64. {
  65. Response.Write("<script>alert('修改失败!')</script>");
  66. }
  67.  
  68. }
  69. }
  70. }

asp.net三层架构增删改查的更多相关文章

  1. 关于C#三层架构增删改查中的“删除”问题

    序: 刚学习C#,经过一段时间学习,现在正在做一个简单的前后台联通的项目(主要是C#三层架构实现增删改查).分享一点儿小经验,也供自己以后可以回头看看自己的码农之路. 内容: 主要分享的是一条删除会用 ...

  2. 关于C#三层架构增删改查中的“添加”问题

    关于“添加”功能的实现比较简单: 先来一个简单的界面: 然后是代码: ··采用的是三层架构的思想写的·· 在DAO中的方法为: (使用了动软自动生成代码) 希望对您有所帮助!

  3. 关于C#三层架构增删改查中的“登录”问题

    先来一个界面: DAO中的方法: 实现代码如下: 这里需要特别注意的是一个“安全性”的考虑: 当登入成功时,把登入时输入的用户名赋值到Session,然后在后面的页面进行判断--此时Session保留 ...

  4. 关于C#三层架构增删改查中的“修改”问题

    先来一个界面图: DAO中的方法: 这里需要获得数据的ID,进而进行操作. 之后是代码的实现: 修改的功能中需要注意的是:根据项目具体需要来判断修改的内容. 希望对您有所帮助!

  5. 关于C#三层架构增删改查中的“查询”问题

    序:问题总是反复出现,可能只是一个小小的问题,但是就像肉中刺. 问题: 关于“姓名”字段的拼接问题 姓名字段的拼接:this.Repeater1.DataSource = db.GetList(&qu ...

  6. 【ASP.NET MVC系列】浅谈jqGrid 在ASP.NET MVC中增删改查

    ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...

  7. Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码

    关于T4代码生成这块,我之前写过几篇帖子,如:<Magicodes.NET框架之路——让代码再飞一会(ASP.NET Scaffolding)>(http://www.cnblogs.co ...

  8. ASP.NET Identity系列02,在ASP.NET MVC中增删改查用户

    本篇体验在ASP.NET MVC中使用ASP.NET Identity增删改查用户. 源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMV ...

  9. Asp.net简单三层+Sqllite 增删改查

    新建项目à新建一个空白解决方案 在Model新建一个实体类 using System; using System.Collections.Generic; using System.Linq; usi ...

随机推荐

  1. MySql-两阶段加锁协议

    此篇博客主要是讲述MySql(仅限innodb)的两阶段加锁(2PL)协议,而非两阶段提交(2PC)协议,区别如下: 2PL,两阶段加锁协议:主要用于单机事务中的一致性与隔离性. 2PC,两阶段提交协 ...

  2. CSS3实例分享之多重背景的实现(Multiple backgrounds)

    CSS3的诞生为我们解决了这一问题,在CSS3里,通过background-image或者background可以为一个容器设置多张背景图像,也就是说可以把不同背景图象只放到一个块元素里. 首先我们来 ...

  3. Windbg分析高内存占用问题

    1. 问题简介 最近产品发布大版本补丁更新,一商超客户升级后,反馈系统经常奔溃,导致超市的收银系统无法正常收银,现场排队付款的顾客更是抱怨声声.为了缓解现场的情况, 客户都是手动回收IIS应用程序池才 ...

  4. Apache Mina-1

    一.mina基础知识: Mina 官方网站:(http://mina.apache.org/) 1.1.Apache Mina是一个能够帮助用户开发高性能和高伸缩性网络应用程序的框架.它通过Java ...

  5. PHP学习笔记 01 之表单传值

    一.HTML传值/PHP接收方法 1.GET(地址栏+问号+数据信息) (1)方式一:表单Form: method = 'get' GET接收数据方式: $_GET['表单元素name对应的值] (2 ...

  6. Shell学习心得(一):变量

     1.begin #!/bin/bash echo "Hello World !" #! 是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种 Shell. ec ...

  7. 如何通过get,set方法访问到父类的私有属性

    刚学习继承的时候,总是会有这样的疑问. 子类继承父类时,会继承所有的非私有的属性和方法.那么在用set方法修改父类的私有属性时,怎么没有报空指针异常呢? 后来仔细想过这个问题,既然没有报空指针,那么在 ...

  8. 【php性能优化】关于写入文件操作的取舍方案

    对于使用php对文件进行写入操作有两种方案一种使用 file_put_contents() 和 fopen()/fwrite()/fclose() 两种方案至于应该怎么选,我觉得应该分情况选择,下面是 ...

  9. css样式的继承性、层叠性 、优先级

    一.css样式的继承性: 作用:给父元素设置一些属性,子元素也可以使用 应用场景: 一般用于设置网页上的一些共性信息,例如网页的文字颜色,字体,文字大小等内容.优化代码,降低工作量 注意点: 1.并不 ...

  10. HTML 练习显示隐藏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...