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" >< ;/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