zoukankan      html  css  js  c++  java
  • 获取当前插入记录的ID

        其中sql语句写法为:INSERT   INTO   table(a,b)   VALUES   (1,2)   SELECT   @@IDENTITY   AS   'Identity' ,然后用SqlCommand 对象的ExecuteScalar()方法获取即可,下面是写好了的一个函数。

    public static int ExecuteSql(string SQLString)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(SQLString, connection))
                    {
                        try
                        {
                            connection.Open();
                            int rows = cmd.ExecuteScalar();
                            return rows;
                        }
                        catch (System.Data.SqlClient.SqlException E)
                        {
                            connection.Close();
                            throw new Exception(E.Message);
                        }
                    }
                }
            } 

  • 相关阅读:
    RPC(简单实现)
    观察者模式
    自省(Introspector)
    Mybatis学习笔记
    Nginx
    AJAX跨域
    手写Tomcat
    监听器模式
    回调
    Temporal Segment Networks
  • 原文地址:https://www.cnblogs.com/catvi/p/1952994.html
Copyright © 2011-2022 走看看