asp.net三层架构增删改查
数据库
use master
if exists (select * from sysdatabases where name='bond')
drop database bond
create database bond
on PRIMARY
(
name='bond_data',
FILENAME='F:\asp\理财代销\management\bond.mdf',
filegrowth=20%,
size=10MB
)
LOG ON
(
name='bond_log',
FILENAME='F:\asp\理财代销\management\bond_log.ldf',
size=3MB,
MAXSIZE=20MB
) use bond
--基金类型表(左用)
if exists (select * from sys.objects where name='jjlx')
drop table jjlx
create table jjlx
(
id int primary key identity(1,1), --id
jjlx varchar(50) not null --基金类型
) --基金类型表增加存储过程
if exists(select * from sys.objects where name='jjlx_add')
drop procedure jjlx_add
go
create proc jjlx_add
@jjlx varchar(50)
as
insert into jjlx values (@jjlx)
go
--基金类型表查询存储过程
if exists(select * from sys.objects where name='p_jjlx')
drop procedure p_jjlx
go
create proc p_jjlx
as
select * from jjlx
go
--基金类型表修改存储过程
if exists(select * from sys.objects where name='jjlx_gai')
drop procedure jjlx_gai
go
create proc jjlx_gai
@id int,
@jjlx varchar(50)
as
UPDATE jjlx SET jjlx=@jjlx where id=@id
go
--基金类型表删除存储过程
if exists(select * from sys.objects where name='jjlx_delete')
drop procedure jjlx_delete
go
create proc jjlx_delete
@id int,
@jjlx varchar(50)
as
delete from jjlx where id=@id and jjlx=@jjlx
go
链接数据库
Web.config
<connectionStrings>
<add name="conn" connectionString="server=.;database=bond;integrated security=true" />
</connectionStrings>
Model层
managementModel类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace managementModel
{
public class jjlxs//基金类型表
{
public int id { set; get; }//id
public string jjlx { set; get; } //基金类型 }
}
DAL层
添加引用 Model层
添加程序集引用 using System.Configuration;
managementDAL类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using managementModel;
namespace managementDAL
{
public class jjlxdal
{
DBHelper db = new DBHelper();
/// <summary>
/// 查询基金类型
/// </summary>
/// <returns></returns>
public DataSet Searchjjlx()
{
string sql = "p_jjlx";
return db.Search(sql);
}
/// <summary>
/// 增加基金类型
/// </summary>
/// <param name="stu"></param>
/// <returns></returns>
public int Insertjjlx(jjlxs stujjlx)
{
string sql = "jjlx_add";
SqlParameter[] para ={
new SqlParameter("@jjlx",stujjlx.jjlx)
};
return db.IUD(sql, para);
}
/// <summary>
/// 修改基金类型
/// </summary>
/// <param name="stu"></param>
/// <returns></returns>
public int Udatejjlx(jjlxs stujjlx)
{
string sql = "jjlx_gai";
SqlParameter[] para ={
new SqlParameter("@id",stujjlx.id),
new SqlParameter("@jjlx",stujjlx.jjlx)
};
return db.IUD(sql, para);
}
/// <summary>
/// 删除基金类型
/// </summary>
/// <param name="stu"></param>
/// <returns></returns>
public int Deletejjlx(jjlxs stujjlx)
{
string sql = "jjlx_delete";
SqlParameter[] para ={
new SqlParameter("@id",stujjlx.id),
new SqlParameter("@jjlx",stujjlx.jjlx)
};
return db.IUD(sql, para);
}
}
}
DBHelper类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace managementDAL
{
public class DBHelper
{
public static string conn = ConfigurationManager.ConnectionStrings["conn"].ToString();
/// <summary>
/// 增删改的方法
/// </summary>
/// <param name="sql">增删改的存储过程</param>
/// <param name="param">存储过程使用的参数</param>
/// <returns></returns>
public int IUD(string sql, SqlParameter[] param)
{
int count = ;
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand com = new SqlCommand(sql, con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddRange(param);
count = com.ExecuteNonQuery();
con.Close();
return count;
}
/// <summary>
/// 查询返回DATASET
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataSet Search(string sql)
{
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(conn);
SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
adapter.Fill(ds);
return ds;
} }
}
BLL层
添加引用 Model层
添加引用 DAL层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using managementDAL;
using managementModel;
using System.Data;
namespace managementBLL
{
public class jjlxbll
{
jjlxdal dal = new jjlxdal();
/// <summary>
/// 查询基金类型
/// </summary>
/// <returns></returns>
public DataSet Searchjjlx() {
return dal.Searchjjlx();
}
/// <summary>
/// 增加基金类型
/// </summary>
/// <param name="stu"></param>
/// <returns></returns>
public bool Insertjjlx(jjlxs stujjlx)
{
bool flag = false;
if (stujjlx.jjlx.Length != )
{
int count = dal.Insertjjlx(stujjlx);
if (count > )
{
flag = true;
}
}
return flag;
}
/// <summary>
/// 修改基金类型
/// </summary>
/// <param name="stujjlx"></param>
/// <returns></returns>
public bool Udatejjlx(jjlxs stujjlx)
{
bool flag = false;
if (stujjlx.jjlx.Length != &&stujjlx.id!=)
{
int count = dal.Udatejjlx(stujjlx);
if (count > )
{
flag = true;
}
}
return flag;
}
/// <summary>
/// 删除基金类型
/// </summary>
/// <param name="stujjlx"></param>
/// <returns></returns>
public bool Deletejjlx(jjlxs stujjlx)
{
bool flag = false;
if (stujjlx.jjlx.Length != && stujjlx.id != )
{
int count = dal.Deletejjlx(stujjlx);
if (count > )
{
flag = true;
}
}
return flag;
}
}
}
UI 层
添加引用 Model层
添加引用 BLL层
基金类型.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="基金类型表.aspx.cs" Inherits="management.index" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label2" runat="server" Text="类型id:"></asp:Label>
<asp:TextBox ID="txtid" runat="server"></asp:TextBox>
<div> </div>
<asp:Label ID="Label1" runat="server" Text="基金类型:"></asp:Label>
<asp:TextBox ID="txtjjlx" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnadd" runat="server" OnClick="btnadd_Click" Text="增加" />
<asp:Button ID="btndelete" runat="server" OnClick="btndelete_Click" Text="删除" />
<asp:Button ID="btngai" runat="server" OnClick="btngai_Click" Text="修改" />
<br />
<table border="">
<tr><th>类型id</th><th>基金类型</th></tr>
<asp:Repeater ID="repjjlx" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("id") %></td>
<td><%#Eval ("jjlx") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</form>
</body>
</html>
基金类型.aspx.cs
基金类型.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using managementBLL;
using System.Data;
using managementModel;
namespace management
{
public partial class index : System.Web.UI.Page
{
jjlxbll bll = new jjlxbll();
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
public void Bind() { this.repjjlx.DataSource = bll.Searchjjlx().Tables[];
this.repjjlx.DataBind();
}
protected void btnadd_Click(object sender, EventArgs e)
{
jjlxs stujjlx = new jjlxs {jjlx=txtjjlx.Text };
if (bll.Insertjjlx(stujjlx))
{
Bind();
Response.Write("<script>alert('增加成功!')</script>");
}
else {
Response.Write("<script>alert('增加失败!')</script>");
}
} protected void btndelete_Click(object sender, EventArgs e)
{
jjlxs stujjlx = new jjlxs();
stujjlx.id = Convert.ToInt32(txtid.Text);
stujjlx.jjlx = txtjjlx.Text;
if (bll.Deletejjlx(stujjlx))
{
Bind();
Response.Write("<script>alert('删除成功!')</script>");
}
else
{
Response.Write("<script>alert('删除失败!')</script>");
}
} protected void btngai_Click(object sender, EventArgs e)
{
jjlxs stujjlx = new jjlxs();
stujjlx.id = Convert.ToInt32(txtid.Text);
stujjlx.jjlx = txtjjlx.Text;
if (bll.Udatejjlx(stujjlx))
{
Bind();
Response.Write("<script>alert('修改成功!')</script>");
}
else
{
Response.Write("<script>alert('修改失败!')</script>");
} }
}
}
asp.net三层架构增删改查的更多相关文章
- 关于C#三层架构增删改查中的“删除”问题
序: 刚学习C#,经过一段时间学习,现在正在做一个简单的前后台联通的项目(主要是C#三层架构实现增删改查).分享一点儿小经验,也供自己以后可以回头看看自己的码农之路. 内容: 主要分享的是一条删除会用 ...
- 关于C#三层架构增删改查中的“添加”问题
关于“添加”功能的实现比较简单: 先来一个简单的界面: 然后是代码: ··采用的是三层架构的思想写的·· 在DAO中的方法为: (使用了动软自动生成代码) 希望对您有所帮助!
- 关于C#三层架构增删改查中的“登录”问题
先来一个界面: DAO中的方法: 实现代码如下: 这里需要特别注意的是一个“安全性”的考虑: 当登入成功时,把登入时输入的用户名赋值到Session,然后在后面的页面进行判断--此时Session保留 ...
- 关于C#三层架构增删改查中的“修改”问题
先来一个界面图: DAO中的方法: 这里需要获得数据的ID,进而进行操作. 之后是代码的实现: 修改的功能中需要注意的是:根据项目具体需要来判断修改的内容. 希望对您有所帮助!
- 关于C#三层架构增删改查中的“查询”问题
序:问题总是反复出现,可能只是一个小小的问题,但是就像肉中刺. 问题: 关于“姓名”字段的拼接问题 姓名字段的拼接:this.Repeater1.DataSource = db.GetList(&qu ...
- 【ASP.NET MVC系列】浅谈jqGrid 在ASP.NET MVC中增删改查
ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...
- Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码
关于T4代码生成这块,我之前写过几篇帖子,如:<Magicodes.NET框架之路——让代码再飞一会(ASP.NET Scaffolding)>(http://www.cnblogs.co ...
- ASP.NET Identity系列02,在ASP.NET MVC中增删改查用户
本篇体验在ASP.NET MVC中使用ASP.NET Identity增删改查用户. 源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMV ...
- Asp.net简单三层+Sqllite 增删改查
新建项目à新建一个空白解决方案 在Model新建一个实体类 using System; using System.Collections.Generic; using System.Linq; usi ...
随机推荐
- Linux上好用的工具集合
1.截图工具 WIndows下有Snipaste,Ubuntu自带的截图工具不能涂鸦等,不好用.Linux下可以使用deepin-screenshot(深度截图,https://www.deepin. ...
- 监督学习——logistic进行二分类(python)
线性回归及sgd/bgd的介绍: 监督学习--随机梯度下降算法(sgd)和批梯度下降算法(bgd) 训练数据形式: (第一列代表x1,第二列代表 x2,第三列代表 数据标签 用 0/ ...
- ERP不规范,同事两行泪
最近的很多次对外交流,都聊到了ERP建设的话题,并且无一例外的不那么让人省心,回想我这么多年走过的ERP坑坑路,在这里也写下经验和总结,希望能给正在或者即将走上ERP建设路的企业一些思考和帮助. 导读 ...
- 【Android Studio安装部署系列】十七、Android studio引用第三方库、jar、so、arr文件
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 在Android开发过程,经常需要用到第三方库以及jar.so.arr文件,那么如何引用到项目中呢?下面简单介绍下. 引用第三方库 ...
- 快速入门:弄懂Kafka的消息流转过程
大家都知道 Kafka 是一个非常牛逼的消息队列框架,阿里的 RocketMQ 也是在 Kafka 的基础上进行改进的.对于初学者来说,一开始面对这么一个庞然大物会不知道怎么入手.那么这篇文章就带你先 ...
- Data Lake Analytics的Geospatial分析函数
0. 简介 为满足部分客户在云上做Geometry数据的分析需求,阿里云Data Lake Analytics(以下简称:DLA)支持多种格式的地理空间数据处理函数,符合Open Geospatial ...
- java 轻量级同步volatile关键字简介与可见性有序性与synchronized区别 多线程中篇(十二)
概念 JMM规范解决了线程安全的问题,主要三个方面:原子性.可见性.有序性,借助于synchronized关键字体现,可以有效地保障线程安全(前提是你正确运用) 之前说过,这三个特性并不一定需要全部同 ...
- Eureka服务配置与进阶
1. Eureka服务配置与进阶 1.1. 主要配置 1.1.1. 服务端(eureka.server.*) enableSelfPreservation默认true,启用注册中心的自保护机制,Eur ...
- 正则表达式在Java中的使用
目录 介绍 从简单例子认识正则表达式匹配 Java中对正则表达式的支持(各种语言有相应的实现) 初步认识 . + * ? 范围 认识\s \w \d - 下面介绍数字和字母的正则表达, 这是编程中使用 ...
- Linux新加磁盘挂载和重启自动挂载
提示两点:*新加的硬盘需要重启服务器fdisk -l才能看到*下面操作要用root账户大概是这样的,查看-分区-格式化-挂载-重启自动挂载1.加硬盘后重启服务器查看[root@test199 ~]# ...