sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
2015-02-10 11:39
871 查看
MySQL存储过程:
Microsoft SQL Server存储过程
csharp 读取MySQL存储过程:
csharp 读取Microsoft SQL Server存储过程
#插入一条返回值 DELIMITER $$ DROP PROCEDURE IF EXISTS `geovindu`.`proc_Insert_BookKindOut` $$ CREATE PROCEDURE `geovindu`.`proc_Insert_BookKindOut` (IN param1Name NVarChar(1000),IN param1Parent Int,OUT ID INT) BEGIN IF NOT EXISTS (SELECT * FROM BookKindList WHERE BookKindName=param1Name) then #如果存在相同的记录,不添加 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存储过程
--插入一条返回值 IF EXISTS (SELECT * FROM sysobjects WHERE [name] = 'proc_Insert_BookKindOut') DROP PROCEDURE proc_Insert_BookKindOut GO CREATE PROCEDURE proc_Insert_BookKindOut ( --@BookKindID Int, @BookKindName NVarChar(1000), @BookKindCode varchar(100), @BookKindParent Int, @BookKindID int output ) AS IF NOT EXISTS (SELECT * FROM BookKindList WHERE [BookKindName]=@BookKindName) BEGIN INSERT INTO BookKindList ( [BookKindName] , [BookKindCode], [BookKindParent] ) VALUES ( @BookKindName , @BookKindCode, @BookKindParent ) select @BookKindID=@@IDENTITY END GO
csharp 读取MySQL存储过程:
/// <summary> /// 追回返回值 /// </summary> /// <param name="bookKindList"></param> /// <param name="id"></param> /// <returns></returns> public int InsertBookKindOut(BookKindListInfo bookKindList,out int id) { int ret = 0; int tid = 0; try { MySqlParameter[] par = new MySqlParameter[]{ new MySqlParameter("?param1Name",MySqlDbType.VarChar,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 读取Microsoft SQL Server存储过程
/// <summary> /// 追加记录返回值 /// </summary> /// <param name="bookKindList"></param> /// <param name="iout"></param> /// <returns></returns> public int InsertBookKindOut(BookKindListInfo bookKindList,out int iout) { int ret = 0; int tou = 0; try { SqlParameter[] par = new SqlParameter[]{ new SqlParameter("@BookKindName",SqlDbType.NVarChar,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
- sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
- SQL Server Database Mirroring - Creating and using Mirror Endpoints in Principal, Mirror and Witness
- Using NOLOCK and READPAST table hints in SQL Server
- Working C# code for MySql5.5 Stored Procedures IN parameters
- Microsoft SQL Server 2005 Stored Procedure Programming in T-SQL & .NET
- FSharp.Data.SqlClient: Seamlessly integrating T-SQL and F# in the same code
- Stored procedures to implement paging for large tables or queries in SQL Server 2005 and SQL Server 2008
- mysql Error Handling and Raising in Stored Procedures
- List the Stored Procedures in a SQL Server database
- Using MERGE in SQL Server to insert, update and delete at the same time
- To SP or not to SP in SQL Server: an argument for stored procedures
- Debugging SQL Server 2005 Stored Procedures in Visual Studio
- Good Practices to Write Stored Procedures in SQL Server
- Using Partitions in a Microsoft SQL Server 2000 Data Warehouse
- The Guru's guide to SQL server stored procedures, XML, and HTML
- Stored procedures versioning with SQL Server and Visual SourceSafe
- Using gdbserver and arm-eabi-gdb to debug native code in Android
- Using the Microsoft Access Providers to Replace the Built-In SQL Server Providers
- Professional SQL Server 2005 CLR Programming: with Stored Procedures, Functions, Triggers, Aggregates and Types