码迷,mamicode.com
首页 > 其他好文 > 详细

返回查询结果的id返回插入数据的id值

时间:2018-08-13 12:24:54      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:esc   tor   ide   生成   sql   sel   ack   hat   string   

begin transaction
declare @error int,@Task_Id int,@TEvents_Id int
set @error=0
insert into dbo.WeChat_Task (WFarm_Id)values (‘0001‘)
--select @Task_Id=@@IDENTITY
set @Task_Id=@@IDENTITY
select @error=@error+@@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 @TEvents_Id=@@IDENTITY
select @error=@error+@@ERROR
insert into dbo.WeChat_Task_EventsLog(TEvents_Id,TEvents_Code,TargetId,LogDescription,PushId)values(@TEvents_Id,‘XCRW0001‘,@Task_Id,‘生成一条现场任务‘,‘0‘)
select @error=@error+@@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值

标签:esc   tor   ide   生成   sql   sel   ack   hat   string   

原文地址:https://www.cnblogs.com/Ly426/p/9466920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!