Sql:mysql and Microsoft SQL Server Stored procedures in, out using CSharp code

Source: Internet
Author: User

MySQL Stored procedures:

#插入一条返回值涂聚文注
DELIMITER $$ DROP PROCEDURE IF EXISTS ' Geovindu '. ' Proc_insert_bookkindout ' $$ CREATE PROCEDURE ' Geovindu '. ' Proc_insert_  Bookkindout ' (in Param1name NVarChar (+), in Param1parent int,out ID int.) BEGIN IF not EXISTS (SELECT * from Bookkindlist WHERE bookkindname=param1name) then #如果存在相同的记录, do not add INSERT into Bookkindlist (bookkindname,bookkindparent) VALUES ( Param1name, param1parent); #set id=last_insert_id () SELECT last_insert_id () into ID; End If; END $$ DELIMITER;

Microsoft SQL Server Stored Procedures

--Insert a return value the poly-Text note
IF EXISTS (SELECT * from sysobjects WHERE [name] = ' proc_insert_bookkindout ') DROP PROCEDURE proc_insert_bookkindout GO CR Eate PROCEDURE proc_insert_bookkindout ([email protected] Int, @BookKindName NVarChar (+), @BookKindCode varchar (100) , @BookKindParent int, @BookKindID int output) as IF not EXISTS (SELECT * from Bookkindlist WHERE [Bookkindname][email PR Otected]) BEGIN INSERT into bookkindlist ([Bookkindname], [Bookkindcode], [bookkindparent]) VALUES (@BookKindName, @B Ookkindcode, @BookKindParent) Select @[email protected] @IDENTITY END GO

CSharp read the MySQL stored procedure:

 <summary>///Recovery return value coating note///</summary>//<param name= "Bookkindlist" ></par am>//<param name= "id" ></param>///<returns></returns> public int Inser            Tbookkindout (bookkindlistinfo bookkindlist,out int id) {int ret = 0;            int tid = 0; try {mysqlparameter[] par = new mysqlparameter[]{new mysqlparameter ("? Param1name", MYSQLDBTYPE.V archar,1000), New Mysqlparameter ("? Param1parent", mysqldbtype.int32,4), New Mysqlparameter ("? ID", Mysqldbtype.                int32,4),}; Par[0].                Value = Bookkindlist.bookkindname; PAR[1].                Value = bookkindlist.bookkindparent; PAR[2].                Direction = ParameterDirection.Output;                ret = Mysqlhelpdu.executesql ("Proc_insert_bookkindout", commandtype.storedprocedure, par); if (Ret > 0) {tid = (int) par[2].   Value;             }} catch (Mysqlexception ex) {throw ex;            } id = tid;        return ret; }

  

CSharp reading Microsoft SQL Server stored Procedures

        <summary>///Append record return value///</summary>//<param name= "Bookkindlist" >&lt ;/param>//<param name= "iout" ></param>///<returns></returns> public in            T insertbookkindout (bookkindlistinfo bookkindlist,out int iout) {int ret = 0;            int tou = 0; try {sqlparameter[] par = new Sqlparameter[]{new SqlParameter ("@BookKindName", Sqldbtype.nvarcha r,1000), New SqlParameter ("@BookKindParent", sqldbtype.int,4), New SqlParameter ("@BookKindID", sqldbtype.int,4                ),}; Par[0].                Value = Bookkindlist.bookkindname; PAR[1].                Value = bookkindlist.bookkindparent; PAR[2].                Direction = ParameterDirection.Output;                ret = Dbhelper.executesql ("Proc_insert_bookkindout", commandtype.storedprocedure, par); if (Ret > 0) {tou = (int) par[2].     Value;           }} catch (SqlException ex) {throw ex;            } iout = tou;        return ret; }

  

Sql:mysql and Microsoft SQL Server Stored procedures in, out using CSharp code

Related Article

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.