数据库使用存储过程
程序员文章站
2022-03-16 11:03:09
public ResultMsg GetUsersCode(int UserId) { ResultMsg msg = new ResultMsg(); var p = new DynamicParameters();// 定义参数 try { p.Add("@UserId", UserId, DbType.Int32); p....
public ResultMsg GetUsersCode(int UserId)
{
ResultMsg msg = new ResultMsg();
var p = new DynamicParameters();// 定义参数
try
{
p.Add("@UserId", UserId, DbType.Int32);
p.Add("@OutCode", null, DbType.Int32,ParameterDirection.Output);
p.Add("@OutEndDate", null, DbType.DateTime, ParameterDirection.Output);
p.Add("@OutCodeId", null, DbType.Int32, ParameterDirection.Output);
var rows = DapperDbHelper.Execute("GetCodeStatic", p, null, null, CommandType.StoredProcedure);//创建数据库带存储过程的链接
int GetCode = p.Get<int>("@OutCode");//读取列出的数据参数
int CodeId = p.Get<int>("@OutCodeId");
DateTime EndDate = p.Get<DateTime>("OutEndDate");
msg.ReturnInt = GetCode;
msg.ReturnDateTime = EndDate;
msg.ReturnString = CodeId.ToString();
}
catch (Exception ex)
{
msg.Success = false;
msg.ErrMsg = ex.Message;
}
return msg;
}
本文地址:https://blog.csdn.net/weixin_40029679/article/details/109013828