csharp: using OleDb Getting the identity of the most recently added record
来源:互联网 发布:算法设计与分析王红梅 编辑:程序博客网 时间:2024/06/02 19:24
/// <summary> /// 执行SQL语句,返回影响的记录数 /// </summary> /// <param name="SQLString">SQL语句</param> /// <returns>影响的记录数</returns> public static int ExecuteSql(string SQLString, params OleDbParameter[] cmdParms) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { using (OleDbCommand cmd = new OleDbCommand()) { try { PrepareCommand(cmd, connection, null, SQLString, cmdParms); int rows = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return rows; } catch (System.Data.OleDb.OleDbException E) { throw new Exception(E.Message); } } } } /// <summary> /// 添加返迴ID值 /// 涂聚文 2014-12-29 /// Geovin Du /// 參考: http://www.mikesdotnetting.com/article/54/getting-the-identity-of-the-most-recently-added-record /// http://stackoverflow.com/questions/186544/identity-after-insert-statement-always-returns-0 /// </summary> /// <param name="SQLString"></param> /// <param name="identity"></param> /// <param name="cmdParms"></param> /// <returns></returns> public static int ExecuteSql(string SQLString, out int identity, params OleDbParameter[] cmdParms) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { using (OleDbCommand cmd = new OleDbCommand()) { try { PrepareCommand(cmd, connection, null, SQLString, cmdParms); int rows = cmd.ExecuteNonQuery(); cmd.CommandText = "Select @@Identity"; identity = (int)cmd.ExecuteScalar(); cmd.Parameters.Clear(); return rows; } catch (System.Data.OleDb.OleDbException E) { throw new Exception(E.Message); } } } }
0 0
- csharp: using OleDb Getting the identity of the most recently added record
- csharp: using OleDb Getting the identity of the most recently added record
- Getting the most out of IDispatch(XYDispDriver)
- 3 Getting the Most Out of Everyday Tools
- Getting the ID of the element that fired an event using jQuery
- Getting the hang of IOPS
- Getting the dimensions of the soft keyboard
- The most important part of the body
- The using of import
- The using of stack
- The first record of a career
- PHP Record the number of login users
- The problem of getting ior by https
- Getting The Hang Of IOPS v1.3
- Getting The Hang Of IOPS v1.3
- Getting rid of the DSL model explorer
- [torch]Getting the Output of a Layer
- The little thing of getting up early
- 回溯法+奇偶剪枝——Hdu 1010 Tempter of the Bone
- Cocos2dx多点触摸实例
- 第一篇博客
- MySQL优化—工欲善其事,必先利其器之EXPLAIN
- First Step
- csharp: using OleDb Getting the identity of the most recently added record
- Unity3D学习之(GUI基础)
- csharp: using OleDb Getting the identity of the most recently added record
- Java的类初始化的详解
- 经典重读《信号与系统》-第五章
- MySQL优化—工欲善其事,必先利其器(2)
- oracle字段名或表名可以以下划线开头吗?
- 知识点摘要-20141229001
- ubuntu 下语系编码转换