MySQL存储过程:

#插入一条返回值涂聚文注
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的更多相关文章

  1. SQL Server :Stored procedures存储过程初级篇

    对于SQL Server,我是个拿来主义.很多底层的原理并不了解,就直接模仿拿着来用了,到了报错的时候,才去找原因进而逐步深入底层.我想,是每一次的报错,逼着我一点点进步的吧. 近期由于项目的原因,我 ...

  2. Part 10 Stored procedures in sql server

    Stored procedures in sql server Stored procedures with output parameters Stored procedure output par ...

  3. 如何將 MySQL 資料庫轉移到 Microsoft SQL Server 與 Azure SQL Database

    MySQL 是相當常用之資料庫伺服器,而微軟雲端服務 Microsoft Azure 上 Azure SQL Database 是一個功能強大且經濟實惠的選擇,透過本篇文章,使用 SQL Server ...

  4. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

  5. 从 Microsoft SQL Server 迁移到 Oracle

    来源于:http://www.oracle.com/technetwork/cn/database/migration/sqlserver-095136-zhs.html Oracle SQL Dev ...

  6. Microsoft SQL - 学习总目录

    Microsoft SQL - 数据库管理系统 Microsoft SQL - 数据类型 Microsoft SQL - 查询与更新 Microsoft SQL - 操作语句 Microsoft SQ ...

  7. Why Stored Procedures?

    http://www.w3resource.com/mysql/mysql-procedure.php Stored procedures are fast. MySQL server takes s ...

  8. Good Practices to Write Stored Procedures in SQL Server

    Reference to: http://www.c-sharpcorner.com/UploadFile/skumaar_mca/good-practices-to-write-the-stored ...

  9. Oracle、Microsoft SQL Server、Mysql

    数据库对比.----1.Oracle:最贵,功能最多,安装最不方便,Oracle环境里的其他相关组件最多,支持平台数量一般,使用中等方便,开发中等方便,运维中等方便,不开源,速度最慢,最安全.---- ...

随机推荐

  1. python基础知识梳理-----4基本数据类型,list ,tuple 操作 ,增删该查,以及其他功能函数

    一:列表的增加 1: append() lis = ['张三','李四','王二码子','李鹏智障'] lis.append('赵武')      # 这种加法是放在最后 print(lis) 输出  ...

  2. Objective-C Associated Objects 的实现原理

    我们知道,在 Objective-C 中可以通过 Category 给一个现有的类添加属性,但是却不能添加实例变量,这似乎成为了 Objective-C 的一个明显短板.然而值得庆幸的是,我们可以通过 ...

  3. hdu 3709 Balanced Number(平衡数)--数位dp

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  4. Python爬虫之XML

    一.请求参数形式为xml 举例说明. 现在有这样一个网址:https://www.runff.com/html/live/s1484.html:想要查询图片列表,打开F12,观察到请求如下: 这里的请 ...

  5. Jira 6.0.5的详细安装及汉化授权

    第一步:安装jdk-6u24-windows-i586.exe (1)下载到oracle官网下装安装 jdk-6u24-windows-i586.exe,http://www.oracle.com/t ...

  6. Python案例之QQ空间自动登录程序实现

    不多说,直接上干货! 工具选择: 电脑系统:win7,32 位,下面第二部安装SetupTools时注意系统版本要求: Python: 2.7.11,  相信只要是2.7的就可以实现: Seleniu ...

  7. 阅读The Java® Language Specification需要知道的术语

    Null Pointer Exception,简称NPE 在java中,static final修饰的是常量.根据编译器的不同行为,常量又可分为编译时常量和运行时常量. 举例说明吧 public st ...

  8. Windows和Ubuntu双系统时间相差8个小时的问题

    由于要学编程,在windows 10上安装了Ubuntu16.04双系统.但是却造成windows时间老是比实际时间慢八个小时,Ubuntu会与网络同步时间,但是在程序中调用主板时间时仍然是UTC时间 ...

  9. mysql 索引数据结构及原理

    原文:http://www.uml.org.cn/sjjm/201107145.asp 1 索引的本质 MySQL官方对索引的定义为:索引(Index)是帮助MySQL高效获取数据的数据结构.提取句子 ...

  10. pureMVC与strangeIoc框架对比

    前言 最近有机会了解到了StrangeIoc框架,就拿来跟自己比较熟悉的pureMVC进行一下简要的对比.这两套开源框架都是基于MVC模式的扩展,pureMVC是一个跨平台跨语言的MVC轻量级应用框架 ...