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. FlowPortal-BPM——创建新模块

    一.设置webconfig (1)数据源设置 添加所有所用到数据库 (2)修改企业信息 二.Main.ashx——添加新的功能选项卡 new { id = "EXECUTE", t ...

  2. noip rp++

    from JOKER-Y

  3. server端获得到client端的IP地址的格式

    使用telnet,ping或其他client连接server端时,server端获得的client端的ip地址取决于client端使用的时ipv4还是ipv6地址. 例: client IPv4地址: ...

  4. Mac下常用按键符号⌘(command)、⌥(option)、⇧(shift)、⇪(caps lock)、⌃(control)、↩(return)、⌅(enter)

    常用符号如下: ⌘(command) ⌥(option) ⇧(shift) ⇪(caps lock) ⌃(control) ↩(return) ⌅(enter) 对应键盘的位置如下: 如果每次都不记得 ...

  5. Highcharts图表.net版开源,支持webform 和 mvc3,完全开源

    Highcharts是一个制作图表的纯Javascript类库,主要特性如下: 兼容性:兼容当今所有的浏览器,包括iPhone.IE和火狐等等: 对个人用户完全免费: 纯JS,无BS: 支持大部分的图 ...

  6. Android中9-Patch图片之理解

    在android中,不仅可以将扩展名为.png,.jpg,.gif的普通图片作为图片资源,而且可以将扩展名为.9.png的9-Patch图片作为图片资源.扩展名为.png,.jpg,.gif的普通图片 ...

  7. 什么是O/RMapping?为什么要用O/R Mapping?

    什么是O/R Mapping ? O/R Mapping 就是有一大堆的类库,我们调用它的时候用面向对象的方式来调,它帮我们翻译成为面向关系的方式. 为什么要用O/R Mapping? 我们编程会更加 ...

  8. Json&XML比较

    1.定义 1.1 XML定义 扩展标记语言 (Extensible Markup Language, XML) ,用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用 ...

  9. ANR机制

    1.什么是ANR(Application Not Responding) 在Android中,应用程序的响应性是由ActivityManager和WindowManager系统服务监视的.当监测到以下 ...

  10. c++ 同步阻塞队列

    参考:<C++11深入应用> 用同步阻塞队列解决生产者消费者问题. 生产者消费者问题: 有一个生产者在生产产品,这些产品将提供给若干个消费者去消费,为了使生产者和消费者能并发执行,在两者之 ...