我无法从存储过程中检索输出信息。我的期望值是基于客户名称参数值与客户关联的数字。我收到的值是-1,但输入的客户名称存在于数据库中。
我怀疑构建后面代码的方式是产生意外的值。如何通过outputCustomerNumber
?
DataManager
值
注意:在SQL Server Management Studio中执行此存储过程时,我收到了预期的值。
public int GetCustomerNumberOnName(string strCustomerName)
{
int customerNumber = 0;
using (DataManager dm = new DataManager())
{
dm.AddParameter("@strCustomerName", strCustomerName, SqlDbType.VarChar, 75, ParameterDirection.Input);
dm.AddParameter("@outCustomerNumber", SqlDbType.Int, int.MaxValue, ParameterDirection.Output);
customerNumber = dm.runSPNonQuery("GetCustomerNumberOnName");
}
return customerNumber;
}
存储过程:
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetCustomerNumberOnName]
@strCustomerName VarChar (75) = NULL,
@strCustomerNumber int = NULL,
--- Output parameter (Integer)
@outCustomerNumber int OUTPUT
AS
SET NOCOUNT ON;
SELECT
@outCustomerNumber = Customer.CMR_NUMBER
FROM
Customer_Information
INNER JOIN
Customer ON Customer_Information.CMR_ROWID = Customer.CMR_ROWID
WHERE
(Customer.CMR_NUMBER = @strCustomerNumber)
OR Customer_Information.CIN_NAME LIKE @strCustomerName
RETURN @outCustomerNumber