获取新插入的数据的自增ID


private const string SQL_INSERT= "insert into 语句;select   @@identity   as   id";//这句

 using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringInventoryDistributedTransaction))
            {


                conn.Open();
                int id = Convert.ToInt32(cmd.ExecuteScalar());  //在打开状态执行这句就OK啦.
                cmd.Parameters.Clear();

            }

你可能感兴趣的:(数据)