csharp: MySQL Stored Procedure using DAL

# 建表 塗聚文 20160907
drop table attendrecord;

create table attendrecord
(
    seq  INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    emp_no varchar(20) null,
    rdate datetime not null,
    rtime time not null,
    rdescription varchar(100),
    rdes_reasnon varchar(100),
    branch varchar(50)
);
#存储过程
# 添加
DELIMITER $$
DROP PROCEDURE  IF EXISTS  `attend`.`proc_Insert_Attendrecord` $$
CREATE PROCEDURE `attend`.`proc_Insert_Attendrecord`
(
	IN param1emp_no VarChar(20),
	IN param1rdate Datetime ,
	IN param1rtime Time,
	IN param1rdescription VarChar(100),
	IN param1rdes_reasnon VarChar(100),
	IN param1branch VarChar(50)
)
BEGIN
INSERT INTO attendrecord
(
	emp_no ,
	rdate ,
	rtime ,
	rdescription ,
	rdes_reasnon ,
	branch
)
	VALUES
(
	param1emp_no ,
	param1rdate ,
	param1rtime ,
	param1rdescription ,
	param1rdes_reasnon ,
	param1branch
); END $$
DELIMITER ;

-- 添加
DELIMITER $$
DROP PROCEDURE  IF EXISTS  proc_Insert_Attendrecord $$
CREATE PROCEDURE proc_Insert_Attendrecord
(
	IN param1emp_no VarChar(20),
	IN param1rdate Datetime ,
	IN param1rtime Time,
	IN param1rdescription VarChar(100),
	IN param1rdes_reasnon VarChar(100),
	IN param1branch VarChar(50)
)
BEGIN
INSERT INTO attendrecord
(
	emp_no ,
	rdate ,
	rtime ,
	rdescription ,
	rdes_reasnon ,
	branch
)
	VALUES
(
	param1emp_no ,
	param1rdate ,
	param1rtime ,
	param1rdescription ,
	param1rdes_reasnon ,
	param1branch
); END $$
DELIMITER ;

#添加
DELIMITER $$
DROP PROCEDURE IF EXISTS proc_Insert_AttendrecordOutput $$
CREATE PROCEDURE proc_Insert_AttendrecordOutput
(
	IN param1emp_no VarChar(20),
	IN param1rdate Datetime,
	IN param1rtime Time,
	IN param1rdescription VarChar(100),
	IN param1rdes_reasnon VarChar(100),
	IN param1branch VarChar(50),
 	out param1seq int
)
BEGIN
INSERT INTO attendrecord
(
	emp_no ,
	rdate ,
	rtime ,
	rdescription ,
	rdes_reasnon ,
	branch
)
	VALUES
(
	param1emp_no ,
	param1rdate ,
	param1rtime ,
	param1rdescription ,
	param1rdes_reasnon ,
	param1branch
);
SELECT LAST_INSERT_ID() into param1seq;
END $$
DELIMITER ;

  

/// <summary>
	/// Attendrecord数据访问层
	///生成時間2016-9-6 17:24:08
	///塗聚文(Geovin Du) 自建代码生成器生成(简单存储过程也可以生成)
	///</summary>
	public class AttendrecordDAL : IAttendrecord
	{
		///<summary>
		/// 追加记录 存储过程
		///</summary>
		///<param name="AttendrecordInfo"></param>
		///<returns></returns>
		public int InsertAttendrecord(AttendrecordInfo attendrecord)
		{
			int ret = 0;
			try
			{
				MySqlParameter[] par = new MySqlParameter[]{
				new MySqlParameter("?param1emp_no",MySqlDbType.VarChar,20),
				new MySqlParameter("?param1rdate",MySqlDbType.Datetime),
				new MySqlParameter("?param1rtime",MySqlDbType.String), //涂聚文注:不能用MySqlDbType.Time否则报错:base {System.Data.Common.DbException} = {"Only TimeSpan objects can be serialized by MySqlTimeSpan"}
				new MySqlParameter("?param1rdescription",MySqlDbType.VarChar,100),
				new MySqlParameter("?param1rdes_reasnon",MySqlDbType.VarChar,100),
				new MySqlParameter("?param1branch",MySqlDbType.VarChar,50),
				};
				par[0].Value = attendrecord.Emp_no;
				par[1].Value = attendrecord.Rdate;
                par[2].Value = attendrecord.Rtime;
				par[3].Value = attendrecord.Rdescription;
				par[4].Value = attendrecord.Rdes_reasnon;
				par[5].Value = attendrecord.Branch;
				ret = DBHelper.ExecuteSql("proc_Insert_Attendrecord", CommandType.StoredProcedure, par);
			}
			catch (MySqlException ex)
			{
				throw ex;
			}
			return ret;
		}
		///<summary>
        /// 追加记录 SQL脚本
		///</summary>
		///<param name="AttendrecordInfo"></param>
		///<returns></returns>
		public int InsertSqlAttendrecord(AttendrecordInfo attendrecord)
		{
			int ret = 0;
			try
			{
				StringBuilder strSql = new StringBuilder();
				strSql.Append("INSERT INTO attendrecord(emp_no,rdate,rtime,rdescription,rdes_reasnon,branch");
				strSql.Append(") VALUES (");
				strSql.Append("?param1emp_no ,?param1rdate ,?param1rtime ,?param1rdescription ,?param1rdes_reasnon ,?param1branch)");
				MySqlParameter[] par = new MySqlParameter[]{
				new MySqlParameter("?param1emp_no",MySqlDbType.VarChar,20),
				new MySqlParameter("?param1rdate",MySqlDbType.Datetime),
				new MySqlParameter("?param1rtime",MySqlDbType.String),
				new MySqlParameter("?param1rdescription",MySqlDbType.VarChar,100),
				new MySqlParameter("?param1rdes_reasnon",MySqlDbType.VarChar,100),
				new MySqlParameter("?param1branch",MySqlDbType.VarChar,50),
				};
				par[0].Value = attendrecord.Emp_no;
				par[1].Value = attendrecord.Rdate;
				par[2].Value = attendrecord.Rtime;
				par[3].Value = attendrecord.Rdescription;
				par[4].Value = attendrecord.Rdes_reasnon;
				par[5].Value = attendrecord.Branch;
				ret = DBHelper.ExecuteSql(strSql.ToString(), CommandType.Text, par);
			}
			catch (MySqlException ex)
			{
				throw ex;
			}
			return ret;
		}

  

时间: 2024-11-08 10:00:17

csharp: MySQL Stored Procedure using DAL的相关文章

MySQL Stored Procedure To Insert Test Record

Create Table create.sql -- ------------------------------------------------------------------------------------------------ -- Target: mariadb Ver 15.1 Distrib 10.4.10-MariaDB, for Linux (x86_64) using readline 5.1 -- Usage: mariadb -uroot -p < ${pat

csharp: Oracle Stored Procedure DAL using ODP.NET

paging : http://www.codeproject.com/Articles/44858/Custom-Paging-GridView-in-ASP-NET-Oracle Oracle sql: --书分类目录kind -- Geovin Du create table BookKindList ( BookKindID INT PRIMARY KEY, BookKindName nvarchar2(500) not null, BookKindParent INT null, Bo

Retrieving Out Params From a Stored Procedure With Python

http://www.rodneyoliver.com/blog/2013/08/08/retrieving-out-params-from-a-stored-procedure-with-python/ AUG 8TH, 2013 I was hacking some python today which calls a stored procedure that sends back an out parameter to indicate whether or not it complet

Home / Python MySQL Tutorial / Calling MySQL Stored Procedures in Python Calling MySQL Stored Procedures in Python

f you are not familiar with MySQL stored procedures or want to review it as a refresher, you can follow the MySQL stored procedures tutorial. We will create two stored procedures for the demonstration in this tutorial. The first stored procedure gets

【机房重构】——存储过程(Stored Procedure)

[前言] 在学习数据库知识时,就曾经接触过存储过程,当时只是如蜻蜓点水一般,短暂的停留,并没有留下什么印象,在进行机房重构学习过程中,又重新认识了存储结构,从开始的抵触,不想用到后来逐渐了解,学着使用,思路越来越清晰,真正去做了才发现了其中的乐趣:常常说学习需要多总结,现在就是在积累,每一次的收获都要整理记录,才能留下深刻的印象,下面就来学习一下存储过程的知识吧. [存储过程的概念] 在采用客户机/服务器(C/S)计算模式的数据库系统中,很多工作可以在客户端完成,也可以在服务器端完成,数据库除了

EntityFramework 学习 一 Stored Procedure

CREATE PROCEDURE [dbo].[GetCoursesByStudentId] -- Add the parameters for the stored procedure here @StudentId int = null AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Inse

Publishing Stored Procedure Execution in Transactional Replication

Replication 不仅可以将Table Article 或 SP Article 推送到subscription,而且还能将sp的execution推送到subscription.推送sp的execution是指将执行sp的command 推送到subscriber去执行, 而不是将sp执行之后产生的大量transaction推送到subscriber上.Transaction是逐个更新Table Article中的数据行. 推送sp的execution来同步subscription的数据

在JDBC中传递table参数给SQL server stored procedure

SQL Server JDBC驱动不支持直接传递Table参数给stored procedure 我的做法是先创建一个临时表,将需要插入的数据先插入到临时表里面,然后把这个临时表作为参数,传送给stored procedure.使用了Preparestatement来避免SQL注入问题. 先创建User Defined Table CREATE TYPE UserIdList AS TABLE( userId uniqueidentifier NOT NULL ); 再创建存储过程: CREAT

Stored Procedure 里的 WITH RECOMPILE 到底是干麻的?

原文:Stored Procedure 里的 WITH RECOMPILE 到底是干麻的? 在 SQL Server 创建或修改「存储过程(stored procedure)」时,可加上 WITH RECOMPILE 选项,但多数文档或书籍都写得语焉不详,或只解释为「每次执行此存储过程时,都要重新编译」.事实上,是指执行此一存储过程时,要强制重新产生「执行计划(execution plan)」,而不要从「缓存(cache)」去取得旧的「执行计划」. SQL Server 在评估与产生「执行计划」