我有一个存储过程
create proc GetCodes
@Code varchar(10),
@Page int = 1,
@Rows int = 10,
@output int output
as
select * from(
Select *, row_number() over(order by code) as RowNum
from codes
where code like '%'+@code+'%'
) as tbl
where @Rows = 0 or RowNum between ((@Page - 1) * @Rows + 1) and (@Page * @Rows)
order by code
set @output = @@ROWCOUNT
我有一个 c# 脚本
SqlCommand cmdSelect = new SqlCommand("GetCodes", SQLData);
cmdSelect.CommandType = CommandType.StoredProcedure;
cmdSelect.Parameters.Add(new SqlParameter("@Code", (Request.QueryString["Code"] != null) ? Request.QueryString["Code"] : ""));
cmdSelect.Parameters.Add(new SqlParameter("@Page", (Request.QueryString["Page"] != null) ? Request.QueryString["Page"] : "1"));
cmdSelect.Parameters.Add(new SqlParameter("@Rows", (Request.QueryString["Rows"] != null) ? Request.QueryString["Rows"] : "10"));
cmdSelect.Parameters.Add(new SqlParameter("@output", SqlDbType.Int));
cmdSelect.Parameters["@output"].Direction = ParameterDirection.Output;
SQLData.Open();
SqlDataReader dtrReader = cmdSelect.ExecuteReader();
int numRows = (int)cmdSelect.Parameters["@output"].Value;
它给了我一个错误“对象引用未设置为对象的实例”的行
int numRows = (int)cmdSelect.Parameters["@output"].Value;
同样的结果,有什么建议吗?