返回查询结果的id返回插入数据的id值
Posted ly426
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了返回查询结果的id返回插入数据的id值相关的知识,希望对你有一定的参考价值。
begin transaction
declare @error int,@Task_Id int,@TEvents_Id int
set @error=0
insert into dbo.WeChat_Task (WFarm_Id)values (‘0001‘)
--select @[email protected]@IDENTITY
set @[email protected]@IDENTITY
select @[email protected][email protected]@ERROR
insert into dbo.WeChat_Task_Events(WFarm_Id,TEvents_Type,TEvents_Code,TEvents_Name,TargetId,StatusId,StatusText,PushId)values(‘0001‘,‘现场任务‘,‘xcrw‘,‘现场任务‘,@Task_Id,‘1‘,‘待办‘,‘0‘)
select @[email protected]@IDENTITY
select @[email protected][email protected]@ERROR
insert into dbo.WeChat_Task_EventsLog(TEvents_Id,TEvents_Code,TargetId,LogDescription,PushId)values(@TEvents_Id,‘XCRW0001‘,@Task_Id,‘生成一条现场任务‘,‘0‘)
select @[email protected][email protected]@ERROR
select @TEvents_Id
if @error<>0
rollback tran
else
commit tran
//HTDbHelper.ExecuteNonQuery(sql);
//int Farm_Id = Convert.ToInt32(Repository.DataContext.ExecuteScalar(CommandType.Text, sql));
int task_id=Convert.ToInt32(HTDbHelper.ExecuteScalar(sql));
ExecuteScalar返回首行首列值
string Farm_Idsql = "SELECT Farm_ID FROM Base_Farm WHERE Farm_Name=‘" + farmname + "‘";
int Farm_Id = Convert.ToInt32(Repository.DataContext.ExecuteScalar(CommandType.Text, Farm_Idsql));
以上是关于返回查询结果的id返回插入数据的id值的主要内容,如果未能解决你的问题,请参考以下文章