日期:2014-05-18  浏览次数:20471 次

来个帮忙 看看 存储过程 事务 上面的问题

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            
            ";




帮忙看看 这段的代码的错误

------解决方案--------------------
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<