sqlserver执行语句返回刚刚插入的ID
#region----新增一条活动表数据---- /// <summary> /// 新增一条活动表数据 /// </summary> /// <param name="appointmentEntity"></param> /// <returns></returns> public int InsertAppointment(Appointment appointmentEntity) { string sql = @" insert into Appointment ( BID,Title,PicUrl,ErpStoreID,Phone, AddressInfo,AddressMap,ApDesc,ApUseDesc,BeginDate, EndDate,Interval,AdvanceCycDay,LimiteBuy,LimiteBuy_Total, LimiteBuy_Day,LimiteBuy_Trade,IsNeedUserPhone,IsValPhone,CusInputeInfo, InterValType,InterValSize,Status,CreateDate,UpdateDate ) values ( @BID,@Title,@PicUrl,@ErpStoreID,@Phone, @AddressInfo,@AddressMap,@ApDesc,@ApUseDesc,@BeginDate, @EndDate,@Interval,@AdvanceCycDay,@LimiteBuy,@LimiteBuy_Total, @LimiteBuy_Day,@LimiteBuy_Trade,@IsNeedUserPhone,@IsValPhone,@CusInputeInfo, @InterValType,@InterValSize,@Status,@CreateDate,@UpdateDate ) SELECT @@IDENTITY as 'ApID' "; //ExecuteScalar,返回刚刚插入的ID的值 var insertResultId = _dbBase.ExecuteScalar(sql, appointmentEntity); int insertId = Convert.ToInt32(insertResultId); return insertId; } #endregion
---系统划分,新增一条规格 insert into ApInterSku ( ApID,BID,InterValType,InterValSize, BeginDate,EndDate, AdvanceDate, CreateDate,UpdateDate, SysBeginDate,SysEndDate ) values ( 666,957,0,1, convert(varchar(100),convert(datetime,'12:00',101),24),convert(varchar(100),convert(datetime,'13:00',101),24), convert(varchar(100),convert(datetime,null,101),23), getdate(),null, convert(varchar(100),convert(datetime,'08:00',101),24),convert(varchar(100),convert(datetime,'18:00',101),24) ) --返回刚刚插入的主键ID的数据 SELECT AvSkuID,BeginDate,EndDate from ApInterSku where AvSkuID=@@IDENTITY