Hi I am working on mvc as part of my learning, So I came accross a situation where I have to pass a datatable to the sp, along with the datatable I have to give one output parameter of int
also of the type. Currently I am using this code
con.Execute("XXXXXXX",
new { @LoginId = LoginId, @City= City, @RegionCode = RegionCode, @CarList= Cars, @CompCOde = COmp},
commandType: CommandType.StoredProcedure);
Here Cars is a datatable so I want to add an output parameter to this , please suggest me a solution.
I would create a parameter list with one designated as ParameterDirection.Output
, then you will be able to read from it with Get
.
I made some assumptions with the following example including a an int output parameter (not tested)
SqlConnection con = new SqlConnection();
DynamicParameters p = new DynamicParameters();
p.Add("@LoginId", LoginId, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
p.Add("@City", City, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
p.Add("@RegionCode", RegionCode, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
p.Add("@CarList", Cars.AsTableValuedParameter());
p.Add("@SomeId", dbType: DbType.Int32, direction: ParameterDirection.Output);
con.Execute("XXXXXXX",p,commandType: CommandType.StoredProcedure);
int someId = p.Get<int>("@SomeId");