我调用 astored procedure并且它有一个int返回值。但是,将值返回到我的后端时出现错误。
public async Task<string> CreatePortfolio(Portfolio portfolio)
{
string statusMessage;
using (SqlConnection conn = new SqlConnection(Connection))
{
SqlParameter returnValue = new SqlParameter(); //Holds the bit that determines if insert was successful or not
SqlCommand command;
command = new SqlCommand();
command.Connection = conn;
conn.Open();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "USP_Add_Portfolio";
command.Parameters.AddWithValue("@portfolioName", portfolio.PortfolioName);
command.Parameters.AddWithValue("@description", portfolio.Description);
command.Parameters.AddWithValue("@createID", portfolio.CreateID);
command.Parameters.AddWithValue("@updateID", portfolio.UpdateID);
command.Parameters.AddWithValue("@statusMessage", SqlDbType.NVarChar).Direction = ParameterDirection.Output;
returnValue.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(returnValue);
int i = await command.ExecuteNonQueryAsync().ConfigureAwait(false);
if(i == 1)
{
statusMessage = command.Parameters["@statusMessage"].Value.ToString();
}
else
{
statusMessage = "Error while adding please contact your administrator";
}
}
return statusMessage;
}
存储过程完成并添加新记录,但出现错误
int i = await command.ExecuteNonQueryAsync().ConfigureAwait(false);
错误:
期待一个 int 但得到 nvarchar
狐的传说
函数式编程
相关分类