我有一个基本的存储过程
ALTER PROCEDURE [dbo].[GetOrdersEmailContent]
@Name nvarchar(50),
@Body nvarchar(2000) OUTPUT
AS
BEGIN
--SET NOCOUNT ON
SET @Body = (SELECT Content
FROM ORDERS_tblEmailContent
WHERE Name = @Name)
END
我使用以下代码从C#调用
using (DbConnection)
{
DbConnection.Open();
using (OdbcCommand DbCommand = DbConnection.CreateCommand())
{
DbCommand.CommandType = CommandType.StoredProcedure;
DbCommand.CommandText = " GetOrdersEmailContent";
DbCommand.Parameters.Add("@Name", OdbcType.NVarChar, 50);
DbCommand.Parameters["@Name"].Value = templateName;
DbCommand.Parameters["@Name"].Direction = ParameterDirection.Input;
DbCommand.Parameters.Add("@Body", OdbcType.NVarChar, 2000);
DbCommand.Parameters["@Body"].Value = DBNull.Value;
DbCommand.Parameters["@Body"].Direction = ParameterDirection.Output;
DbCommand.ExecuteNonQuery();
emailBody = DbCommand.Parameters["@Body"].Value.ToString();
}
}
DbConnection.Close();
当ExecuteNonQuery
运行时,它会返回以下错误:
错误[42000] [Microsoft] [SQL Server Native Client 11.0] [SQL Server]过程或函数' GetOrdersEmailContent'期望参数' @ Name',这是未提供的。
任何人都可以提供建议吗?我查看了其他类似的问题,但没有一个解决方案适用或解决问题
答案 0 :(得分:0)
考虑templateName
没有空。无需为@Name
指定方向:
using (DbConnection)
{
DbConnection.Open();
using (OdbcCommand DbCommand = DbConnection.CreateCommand())
{
DbCommand.CommandType = CommandType.StoredProcedure;
DbCommand.CommandText = " GetOrdersEmailContent";
DbCommand.Parameters.Add("@Name", OdbcType.NVarChar, 50);
DbCommand.Parameters["@Name"].Value = templateName;
DbCommand.Parameters.Add("@Body", OdbcType.NVarChar, 2000);
DbCommand.Parameters["@Body"].Value = DBNull.Value;
DbCommand.Parameters["@Body"].Direction = ParameterDirection.Output;
DbCommand.ExecuteNonQuery();
emailBody = DbCommand.Parameters["@Body"].Value.ToString();
}
}
DbConnection.Close();