3

I have to call Stored Procedure in which parameters are char and VarBinary(MAX). I need to call this stored procedure from C# code using Dapper. But I am not able to find any parameter supported by dapper.

SP:

ALTER PROCEDURE [dbo].[uspTest]      
 , @Param1   CHAR(1)        
 , @Param2   VARBINARY(MAX)=null

C#:

DynamicParameters parameter = new DynamicParameters();
parameter.Add("@Param1", email.SenderType, DbType.char, ParameterDirection.Input);
parameter.Add("@Param2", email.AttachedFileStream, DbType.varbinary, ParameterDirection.Input);

Compilation Error:

DBType does not contain definition for char and varbinary

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

2 Answers2

3

This problem doesn't have anything to do with Dapper, you're attempting to access enum members that simply don't exist.

The DbType enum does not contain members named char or varbinary.

Instead of char use AnsiStringFixedLength and instead of varbinary use Binary.
Also, at least in the first parameter, you should also include the size:

DynamicParameters parameter = new DynamicParameters();
parameter.Add("@Param1", email.SenderType, DbType.AnsiStringFixedLength, ParameterDirection.Input, 1);
parameter.Add("@Param2", email.AttachedFileStream, DbType.Binary, ParameterDirection.Input);
Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
0

You can use this;

db.Execute("Sql Query", new Dapper.DynamicParameters(new Dictionary<string, object>() { { "ColumnName", "ValueObject" } }));

You must use variable type on Enum, like this;

public enum TestEnum : byte { // Values }

dcansyn
  • 78
  • 6