How to return image from Stored procedure using Dapper in C#?
I have a stored procedure with multiple out's and a return value. I want to read the return type in C#
PFB the Code and Stored procedure. Please suggest me how to resolve this.
CREATE PROCEDURE procedure_Sessions
@id nvarchar(80),
@IsLocked bit OUTPUT,
@LockAge int OUTPUT
AS
DECLARE @textptr AS varbinary(16)
DECLARE @length AS int
DECLARE @now AS datetime
SET @now = GETUTCDATE()
-- Update Query Begins not complete Query example --
@textptr = CASE IsLocked
WHEN 0 THEN TEXTPTR(State)
ELSE NULL
END
@length = CASE IsLocked
WHEN 0 THEN DATALENGTH(State)
ELSE NULL
END
-- Update Query Ends--
IF @length IS NOT NULL BEGIN
READTEXT dbo.commons.State @textptr 0 @length
END
RETURN 0
C# Code:
DynamicParameters dp = new DynamicParameters();
dp.Add("@Id", Id);
dp.Add("@IsLocked", dbType: DbType.Boolean, direction: ParameterDirection.Output);
dp.Add("@LockAge", dbType: DbType.Int32, direction: ParameterDirection.Output);
dp.Add("ReturnValue", dbType: DbType.Object, direction: ParameterDirection.ReturnValue);
connection.Query<byte>("Exclusive", dp, commandType: CommandType.StoredProcedure);
isLocked = dp.Get<bool>("@IsLocked");
lockAge = dp.Get<int>("@LockAge");
var returnvalue = dp.Get<object>("ReturnValue");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…