Home  >  Article  >  Database  >  SQL插入数据同时返回当前自增长ID_MySQL

SQL插入数据同时返回当前自增长ID_MySQL

WBOY
WBOYOriginal
2016-06-01 13:52:191260browse

今天遇一网友问。关于如何获取插入表数据,同时返回当前自增长的ID。(是mysql库)。

回复:SELECT LAST_INSERT_ID()。SELECT @@IDENTITY接可。但到下午那兄弟还没搞定。因为不知道怎么运行。。项目都是三层的。基本是写在DBHELPER中。原因是其写入了:cmd.ExecuteNonQuery(); ---这是执行非查询语句返回受影响的行数。

其实是应该写入:cmd.ExecuteScalar();返回首行首列。可能是因为helper里面注释为:

     ///


        /// 执行一条计算查询结果语句,返回查询结果(object)。
        ///

        /// 计算查询结果语句
        /// 查询结果(object)误导的原因。。浪费半天时间。。

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn