来个帮忙 看看 存储过程 事务 上面的问题
时间:2011-12-01
来源:互联网

C# code
sql+=@"BEGIN TRANSACTION if not exists(select * from T_PersonInfo where id=@empid) INSERT INTO T_PersonInfo(id,name,k_rate,AdminRate,SubsidyRate,bank_account,bank_Name,bank_City,company_place,orgId,dept_cost_center,status,person_cost_center,job,jobPart,part_info,in_job_date,work_city,phone,email,education,sex,person_id,passport_id,birthday,nationality,politics,marriage,reg_place,reg_address,linkman,emergent_phone,live_place,live_address,zip_code,contract_timelimit,contract_date_op,contract_date_ed,probation,change_date,BenchId,stateFlag) select @empid,@name,@k_rate,@AdminRate,@SubsidyRate,@bank_account,@bank_Name,@bank_City,@company_place,@orgId,@dept_cost_center,@status,@person_cost_center,@job,@jobPart,@part_info,@in_job_date,@work_city,@phone,@email,@education,@sex,@person_id,@passport_id,@birthday,@nationality,@politics,@marriage,@reg_place,@reg_address,@linkman,@emergent_phone,@live_place,@live_address,@zip_code,@contract_timelimit,@contract_date_op,@contract_date_ed,@probation,@change_date,@benchId,@stateFlag if @@error<>0 ROLLBACK TRANSACTION return "; sql+=@" Update T_ArchiveInfo Set staffId=@empid,lastModifyDate=@lastModifyDate where staffId=@oldId if @@error<>0 ROLLBACK TRANSACTION return "; sql+=@" if not exists(select * from T_EmailGroupRelation where staffId=@empid) "; for(int i=0;i<list.Count;i++){ sql+=@"Insert Into T_EmailGroupRelation(id,staffId,emailGroup,bolSend) values(@id,@empid,@emailGroup"+i+",@bolSend"+i+");"; } sql+=@" if @@error<>0 ROLLBACK TRANSACTION return if not exists(select * from T_EmailGroupRelation where staffId=@oldId) delete T_PersonInfo where id=@oldId if @@error<>0 ROLLBACK TRANSACTION return else COMMIT TRANSACTION ";
帮忙看看 这段的代码的错误
作者: shwicho 发布时间: 2011-12-01
sql+=@"BEGIN TRANSACTION
if not exists(select * from T_PersonInfo where id=@empid)
INSERT INTO T_PersonInfo(id,name,k_rate,AdminRate,SubsidyRate,bank_account,bank_Name,bank_City,company_place,orgId,dept_cost_center,status,person_cost_center,job,jobPart,part_info,in_job_date,work_city,phone,email,education,sex,person_id,passport_id,birthday,nationality,politics,marriage,reg_place,reg_address,linkman,emergent_phone,live_place,live_address,zip_code,contract_timelimit,contract_date_op,contract_date_ed,probation,change_date,BenchId,stateFlag)
select @empid,@name,@k_rate,@AdminRate,@SubsidyRate,@bank_account,@bank_Name,@bank_City,@company_place,@orgId,@dept_cost_center,@status,@person_cost_center,@job,@jobPart,@part_info,@in_job_date,@work_city,@phone,@email,@education,@sex,@person_id,@passport_id,@birthday,@nationality,@politics,@marriage,@reg_place,@reg_address,@linkman,@emergent_phone,@live_place,@live_address,@zip_code,@contract_timelimit,@contract_date_op,@contract_date_ed,@probation,@change_date,@benchId,@stateFlag
if @@error<>0
ROLLBACK TRANSACTION return
";
-->
sql+=@"BEGIN TRANSACTION
if not exists(select * from T_PersonInfo where id=@empid)
begin
INSERT INTO T_PersonInfo(id,name,k_rate,AdminRate,SubsidyRate,bank_account,bank_Name,bank_City,company_place,orgId,dept_cost_center,status,person_cost_center,job,jobPart,part_info,in_job_date,work_city,phone,email,education,sex,person_id,passport_id,birthday,nationality,politics,marriage,reg_place,reg_address,linkman,emergent_phone,live_place,live_address,zip_code,contract_timelimit,contract_date_op,contract_date_ed,probation,change_date,BenchId,stateFlag)
select @empid,@name,@k_rate,@AdminRate,@SubsidyRate,@bank_account,@bank_Name,@bank_City,@company_place,@orgId,@dept_cost_center,@status,@person_cost_center,@job,@jobPart,@part_info,@in_job_date,@work_city,@phone,@email,@education,@sex,@person_id,@passport_id,@birthday,@nationality,@politics,@marriage,@reg_place,@reg_address,@linkman,@emergent_phone,@live_place,@live_address,@zip_code,@contract_timelimit,@contract_date_op,@contract_date_ed,@probation,@change_date,@benchId,@stateFlag
if @@error<>0
begin
ROLLBACK TRANSACTION return
end
end
";
其他段类似修改
if not exists(select * from T_PersonInfo where id=@empid)
INSERT INTO T_PersonInfo(id,name,k_rate,AdminRate,SubsidyRate,bank_account,bank_Name,bank_City,company_place,orgId,dept_cost_center,status,person_cost_center,job,jobPart,part_info,in_job_date,work_city,phone,email,education,sex,person_id,passport_id,birthday,nationality,politics,marriage,reg_place,reg_address,linkman,emergent_phone,live_place,live_address,zip_code,contract_timelimit,contract_date_op,contract_date_ed,probation,change_date,BenchId,stateFlag)
select @empid,@name,@k_rate,@AdminRate,@SubsidyRate,@bank_account,@bank_Name,@bank_City,@company_place,@orgId,@dept_cost_center,@status,@person_cost_center,@job,@jobPart,@part_info,@in_job_date,@work_city,@phone,@email,@education,@sex,@person_id,@passport_id,@birthday,@nationality,@politics,@marriage,@reg_place,@reg_address,@linkman,@emergent_phone,@live_place,@live_address,@zip_code,@contract_timelimit,@contract_date_op,@contract_date_ed,@probation,@change_date,@benchId,@stateFlag
if @@error<>0
ROLLBACK TRANSACTION return
";
-->
sql+=@"BEGIN TRANSACTION
if not exists(select * from T_PersonInfo where id=@empid)
begin
INSERT INTO T_PersonInfo(id,name,k_rate,AdminRate,SubsidyRate,bank_account,bank_Name,bank_City,company_place,orgId,dept_cost_center,status,person_cost_center,job,jobPart,part_info,in_job_date,work_city,phone,email,education,sex,person_id,passport_id,birthday,nationality,politics,marriage,reg_place,reg_address,linkman,emergent_phone,live_place,live_address,zip_code,contract_timelimit,contract_date_op,contract_date_ed,probation,change_date,BenchId,stateFlag)
select @empid,@name,@k_rate,@AdminRate,@SubsidyRate,@bank_account,@bank_Name,@bank_City,@company_place,@orgId,@dept_cost_center,@status,@person_cost_center,@job,@jobPart,@part_info,@in_job_date,@work_city,@phone,@email,@education,@sex,@person_id,@passport_id,@birthday,@nationality,@politics,@marriage,@reg_place,@reg_address,@linkman,@emergent_phone,@live_place,@live_address,@zip_code,@contract_timelimit,@contract_date_op,@contract_date_ed,@probation,@change_date,@benchId,@stateFlag
if @@error<>0
begin
ROLLBACK TRANSACTION return
end
end
";
其他段类似修改
作者: Haiwer 发布时间: 2011-12-01
先试试 ,先行谢过
作者: shwicho 发布时间: 2011-12-01
应该begin..end一一对应的吧。
作者: fredrickhu 发布时间: 2011-12-01
为什么不写到存储过程里,拼接字符串很容易出错,你可以调试出来看看你的sql
作者: ssp2009 发布时间: 2011-12-01
因为有封装好的 底层代码,直接 操作 数据工厂
作者: shwicho 发布时间: 2011-12-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28