Interview Questions with answers
Transactions :
database level transactions
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[csp_DeleteExamQuestion]
@intExaminationQuestionId int,
@intIsSucess int OUTPUT
AS
BEGIN
DECLARE @intExaminationId AS INT
DECLARE @intQuestionSeqId AS TINYINT
DECLARE @intSectionId AS TINYINT
SET @intIsSucess = 0;
BEGIN TRANSACTION
BEGIN TRY
SELECT
@intExaminationId = intExaminationId ,
@intQuestionSeqId = intQuestionSeqId,
@intSectionId = intSectionId
FROM tblExaminationQuestion
WHERE intExaminationQuestionId = @intExaminationQuestionId
Print @intExaminationId
Print @intQuestionSeqId
DELETE FROM tblExaminationQuestion
WHERE intExaminationQuestionId = @intExaminationQuestionId
UPDATE tblExaminationQuestion
SET intQuestionSeqId = (intQuestionSeqId -1)
WHERE intExaminationId = @intExaminationId
AND intSectionId = @intSectionId
AND intQuestionSeqId > @intQuestionSeqId
SET @intIsSucess = 1
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
END CATCH;
IF @@TRANCOUNT > 0
BEGIN
COMMIT TRANSACTION;
SET @intIsSucess = 1
END
RETURN @intIsSucess
END
Ado.net Level Transactions :
public int AddExaminationSections(bool isAdd,
List examinationSectionList)
{
int returnId = 0;
try
{
using (TransactionScope scope = new TransactionScope())
{
int returnExaminationSectionId = 0;
bool tempIsAdd = true;
foreach (ExaminationSection examinationSection in examinationSectionList)
{
if (examinationSection != null)
{
if (!isAdd && examinationSection.ExaminationSectionId > 0)
{
tempIsAdd = false;
}
}
returnExaminationSectionId = AddExaminationSection(tempIsAdd,
examinationSection.ExaminationSectionId,
examinationSection.ExaminationId,
examinationSection.SectionId,
examinationSection.NoOfQuestions);
if (returnExaminationSectionId > 0)
{
returnId = examinationSection.ExaminationId;
}
else
{
return 0;
}
}
if (returnExaminationSectionId > 0)
{
scope.Complete();
//returnId = examinationSection.;
}
}
}
catch (Exception ex)
{
ELearning.ErrorLogger.Error.WriteErrorLog(ex);
}
return returnId;
}
0 Response to "Interview Questions with answers"
Post a Comment