Csharp:mysql Stored Procedure using DAL

Source: Internet
Author: User

# Built-in 20160907drop table attendrecord;create table Attendrecord (seq INT not NULL PRIMARY KEY auto_increment, EM P_no varchar NULL, rdate datetime NOT NULL, rtime time NOT NULL, rdescription varchar, Rdes_reasnon V Archar (+), branch varchar); #存储过程 # Add delimiter $ $DROP PROCEDURE IF EXISTS ' attend '. ' Proc_insert_attendrecord ' $$ CREATE PROCEDURE ' attend '. ' Proc_insert_attendrecord ' (in Param1emp_no VarChar), in Param1rdate Datetime, in Param1rtime time,in param1rdescription varchar (+), in Param1rdes_reasnon varchar (+), in Param1branch varchar (50)) Begininsert into Attendrecord (Emp_no, Rdate, Rtime, rdescription, Rdes_reasnon, Branch) VALUES (Param1emp_no, Param1rdate, Param1rtime, Param1rdescription, Param1rdes_reasnon, param1branch); END $ $DELIMITER;--Add DELIMITER $ $DROP PROCEDURE IF EXISTS proc_insert_attendrecord $ $CREATE PROCEDURE Proc_insert_atten Drecord (in Param1emp_no VarChar), in Param1rdate Datetime, in Param1rtime time,in param1rdescriptIon varchar (+), in Param1rdes_reasnon varchar (+), in Param1branch varchar (a)) Begininsert 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), in Param1rdate datetime,in param1rtime time,in param1rdescription varchar (+), in Param1rdes_reasnon varchar (+), in param1branch varchar (+), out param1seq int) Begininsert 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 data Access Layer//generated time 2016-9-6 17:24:08///(Geovin Du) built-in code generator (simple stored procedure can also be generated)///</ Summary>public class attendrecorddal:iattendrecord{///<summary>///append record stored procedure///</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),//Xiaozu Note: cannot use mysqldbtype.time otherwise error: 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),};p ar[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>///Append record SQL script///</summary>///<param name= "Attendrecordinfo" ></param>///<r eturns></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),};p ar[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;}

  

Csharp:mysql Stored Procedure using DAL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.