00问答网
所有问题
sql语句中有insert然后有个select@@identity,该怎么执行,C#
如题所述
举报该问题
推荐答案 2019-11-05
它依旧是select语句啊
肯定是用SqlDataReader接受
并接读取最后的结果
。你在SQl里面执行一下这个语句,它是会出现一个表,所以就跟执行一班查询一样执行就可以了!
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://00.wendadaohang.com/zd/nDZjerInnZ00e0r0rTT.html
其他回答
第1个回答 2019-03-22
string
sql="insert
into
users
values('admin','admin','男');select
@@Identity";
sql语句拼装在一起执行,等于是先执行插入操作,然后返回所插入的数据的id
这条sql语句直接
用sqlcommand的ExecuteNonQuery
方法执行
会返回所插入的数据的的id号
相似回答
sql语句中有insert然后有个select@identity,该怎么执行,C
答:
就是在你对有 identity 列插入完成后调用的。IDENTITY 返回最后插入的标识值的系统函数。如果语句未影响任何包含标识列的表,则 @@IDENTITY 返回 NULL.出现
INSERT
或
SELECT
INTO 语句失败或大容量复制失败,或者事务被回滚的情况时
,@@IDENTITY
值不会恢复为以前的设置。SCOPE_IDENTITY() 返回插入到同...
sql语句中有insert然后有个select@identity,该怎么执行
答:
你说的应该是@@identity 用
select @@identity
得到上一次插入记录时自动产生的ID 如果你使用存储过程的话,将非常简单,代码如下:SET @NewID=@@IDENTITY 说明:在一条
INSERT
、SELECT INTO 或大容量复制语句完成后,@@IDENTITY 中包含此语句产生的最后的标识值。若此语句没有影响任何有标识列的表,则 ...
c#
.net关于
@@identity
答:
Insert
into [tb_Member]([Name],[Password])values(@Name,@Password)
select @
MemberID=
@@identity
你先在sql 数据库
执行
这段代码 看看能不能运行在说··先随便赋值·看看sql 有没有错··估计你
的sql 语句有
误·你是不是添加数据的时候·同时返回添加的ID?如果是你就在
insert
添加完之后 ...
sql
取新增ID(
C#
.net程序)
答:
String sql = "begin transaction;
insert
into table1(name,age)values('测试',22);
select
newID = max(idnetity) from table1;commit transaction"SqlCommand cmd = new SqlCommand(
sql,sql
Conn);cmd.Parameters.AddRange(sqlParameters);int val = cmd.ExecuteScalar();return val;//用transaction...
大家正在搜
insert select语句
identity insert
identify_insert
将select结果insert
insert和select一起用
insert包含select
insert select效率
insert select 组合
insert嵌套select
相关问题
sql语句中有insert然后有个select@@ident...
sql语句中有insert然后有个select@@ident...
sql语句中有insert然后有个select@@ident...
sql语句中有insert然后有个select@@ident...
select @@IDENTITY 怎么用C#输出出来
c#如何得到自增值字段的值?
C#中怎么返回数据库的标识列 select @@identi...
c#连接sql数据库 存储过程用了@@identity就出错