Hi everyone,
I have finyearwise data in finyearhosteldetails table. But i not able to update them Whenever i click button update it is giving me the following error.
transaction count after execute indicates a mismatching number of begin and commit statements. previous count = 1, current count = 0
How to solve this?? Please give the solution as it under top priority
My sp is:
ALTER PROCEDURE [dbo].[UpdateBasicHostelDetails]
(
@DistrictCd int,
@TalukCd int,
@VillageCd int,
@HostName varchar(150),
@PreOrPost int,
@ScOrSt varchar(10),
@BoysOrGirlsOrCoEd int,
@Sant int,
@Admt int,
@WardenName varchar(100),
@WardenMobNo float ,
@WardenMobNo2 float,
@NeighborName1 varchar(100),
@Neigh1MobNo float,
@NeighborName2 varchar(100),
@Neigh2MobNo float,
@Location varchar(150),
@HostelAdd varchar(500),
@User varchar(25),
@FinYear varchar(25),
@Ip varchar(150),
@HostelCd int,
@seccode nvarchar(max),
@plan nvarchar(max)
)
as
begin
begin try
begin transaction
DECLARE @Count int
update HostelDetails
set districtcd=@DistrictCd,talukcd=@TalukCd, HostelName=@HostName ,Location=@Location ,Hostel_Address=@HostelAdd ,
Sc_St_Hostel=@ScOrSt,B_G_Coed=@BoysOrGirlsOrCoEd,Pre_Post=@PreOrPost ,
Sanctioned=@Sant ,Admitted=@Admt ,Warden_Name=@WardenName ,Warden_Mobile_No1=@WardenMobNo ,
Warden_Mobile_No2=@WardenMobNo2 ,Neighbor1_Name=@NeighborName1 ,Neighbor1_MobNo=@Neigh1MobNo ,
Neighbor2_Name=@NeighborName2 ,Neighbor2_MobNo=@Neigh2MobNo ,status=1,Sector=@seccode,HostelPlan=@plan
where Hostelcd=@HostelCd
set @Count =(select count(*) from FinYearHostelDetails where Hostelcd =@HostelCd and (Fin_year=@FinYear))
if (@Count = 0)
Begin
insert into FinYearHostelDetails(districtcd,talukcd,Hostelcd,HostelName,Sc_St_Hostel,B_G_Coed,Pre_Post,
Sanctioned,Admitted,Warden_Name,Warden_Mobile_No1,Warden_Mobile_No2,Neighbor1_Name,
Neighbor1_MobNo,Neighbor2_Name,Neighbor2_MobNo,Location,Hostel_Address,Status,
Fin_year,Sector,HostelPlan)
values (@DistrictCd,@TalukCd,@HostelCd,@HostName ,@ScOrSt ,@BoysOrGirlsOrCoEd ,@PreOrPost ,@Sant ,@Admt ,@WardenName ,
@WardenMobNo ,@WardenMobNo2 ,@NeighborName1 ,@Neigh1MobNo ,@NeighborName2 ,@Neigh2MobNo ,@Location ,
@HostelAdd ,0,@FinYear,@seccode,@plan)
End
Else
Begin
update FinYearHostelDetails
set districtcd=@DistrictCd,talukcd=@TalukCd, HostelName=@HostName ,Location=@Location ,Hostel_Address=@HostelAdd ,
Sc_St_Hostel=@ScOrSt ,B_G_Coed=@BoysOrGirlsOrCoEd ,Pre_Post=@PreOrPost ,
Sanctioned=@Sant ,Admitted=@Admt ,Warden_Name=@WardenName ,Warden_Mobile_No1=@WardenMobNo ,
Warden_Mobile_No2=@WardenMobNo2 ,Neighbor1_Name=@NeighborName1 ,Neighbor1_MobNo=@Neigh1MobNo ,
Neighbor2_Name=@NeighborName2 ,Neighbor2_MobNo=@Neigh2MobNo ,status = 0,Fin_year=@FinYear,Sector=@seccode,HostelPlan=@plan
where Hostelcd =@HostelCd
End
commit transaction
End Try
Begin Catch
BEGIN
ROLLBACK TRANSACTION
END
End catch
end