【发布时间】:2021-01-25 15:04:49
【问题描述】:
我正在编写一个存储过程来捕获用户在 Web 应用程序中所做的某些注释。程序存储笔记,我需要输出参数来通知用户他/她的笔记是否被正确捕获。但是,我的输出参数有问题。
这是我的存储过程:
CREATE PROCEDURE captureNotes (
@IdFile bigint,
@IdSection int,
@Notes varchar(500),
@IsOk bit,
@User varchar(100),
@Bit bit OUTPUT)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
--Checking if we are going to overwrite previous notes--
DECLARE @Count int;
SET @Count = (SELECT
COUNT(IdFile)
FROM WebValidation
WHERE IdFile = @IdFile
AND IdSection = @IdSection
AND User = @User);
IF @Count > 0
BEGIN
UPDATE WebValidation
SET Notes = @Notes,
IsOk = @IsOk, Date = GETDATE()
WHERE IdFile = @IdFile
AND IdSection = @IdSection
AND User = @User
SET @Bit=1;
END
ELSE
BEGIN
INSERT INTO WebValidation
VALUES (@IdFile, @IdSection, @Notes, @IsOk, @User, GETDATE());
SET @Bit=1;
END
SET @Bit = 1;
SET NOCOUNT OFF
END TRY
BEGIN CATCH
SET @Bit = 0;
SET NOCOUNT OFF;
END CATCH
END
我的 C# 代码
public int captureNotes(Int64 idFile, int idSection,
string notes, bool isOk, string user)
{
try
{
db = DatabaseFactory.CreateDatabase("CnxPrincipal");
cmd = db.GetStoredProcCommand("[captureNotes]");
cmd.CommandTimeout = DBExecutionTimeout;
db.AddInParameter(cmd, "@IdFile", DbType.Int64, idFile);
db.AddInParameter(cmd, "@IdSection", DbType.Int16, idSection);
db.AddInParameter(cmd, "@Notes", DbType.String, notes);
db.AddInParameter(cmd, "@IsOk", DbType.Boolean, isOk);
db.AddInParameter(cmd, "@User", DbType.String, user);
int result = 0;
db.AddOutParameter(cmd, "@Bit", DbType.Boolean, result);
db.ExecuteNonQuery(cmd);
return result;
} catch (Exception ex) { throw ex; }
finally { cmd.Dispose(); db = null; }
}
代码将始终返回 0,尽管注释已成功添加。我究竟做错了什么? 感谢您的宝贵时间。
【问题讨论】:
标签: c# sql asp.net .net enterprise-library