我使用以下代码使用存储过程
获取客户详细信息 public List<Customer> GetPacketReconciliation(int customerId, int size, DateTime billDate, ref DateTime lastRunDate)
{
List<Customer> getCustomer = new List<Customer>();
SqlParameter[] arParms = new SqlParameter[4];
arParms[0] = new SqlParameter("@Cust_ID", SqlDbType.Int);
arParms[0].Value = customerId;
arParms[1] = new SqlParameter("@Size", SqlDbType.Int);
arParms[1].Value = size;
arParms[2] = new SqlParameter("@Last_Run_Date", SqlDbType.DateTime);
arParms[2].Direction = ParameterDirection.InputOutput;
arParms[2].Value = lastRunDate;
arParms[3] = new SqlParameter("@Bill_Date", SqlDbType.DateTime);
arParms[3].Value = billDate;
using (SqlConnection sqlCon = new SqlConnection(this.GetConnectionString()))
{
sqlCon.Open();
using (SqlDataReader reader = SqlHelper.ExecuteReader(sqlCon, CommandType.StoredProcedure, "dbo.GetCustomer", arParms))
{
if (reader.HasRows)
{
getCustomer= MapToEntityCollection<Customer>(reader);
}
}
}
if (arParms[2].Value != DBNull.Value)
{
lastRunDate = Convert.ToDateTime(arParms[2].Value);
}
return getCustomer;
}
存储过程
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[GetCustomer]
@Cust_ID SMALLINT,
@Size INT,
@Last_Run_Date DATETIME OUTPUT,
@Bill_Date DATETIME
AS
BEGIN
END
我在这里使用一个ref
变量lastRunDate
。调试时我可以看到lastdate
中的sqlparameter
值设置正确。但是当我使用sql profiler查看它时,我可以看到lastRunDate
设置为null
。我像arParms [2] .Value = DateTime.Parse(“2017-01-01”)硬编码,它的工作原理。参考参数的任何问题??
任何人在此代码中看到任何问题..