大家好,我正在尝试为某些实体创建分页,我有这样的签名功能public static List<someClass> somePageingFunc(int curentPage,int pageSize,int out maxCount)
我不能使用存储过程我是 sql 新手请告诉我我做错了什么
string comandStr = "DECLARE @MaxCount int SELECT @MaxCount= Count (*) FROM tbMediaItems"+
" SELECT top(@NumOfRows) * FROM ( SELECT RowNum = ROW_NUMBER() OVER ("+
"ORDER BY Artist), * FROM tbMediaItems) AS a WHERE RowNum > (@NumOfRows * (@CurrentPage - 1)) RETURN @MaxCount";
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = comandStr;
cmd.CommandType = CommandType.Text;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@NumOfRows", SqlDbType.Int).Value = pageSize;
cmd.Parameters.Add("@CurrentPage", SqlDbType.Int).Value = curentPage;
cmd.Parameters.Add("@Result", SqlDbType.Int).Direction =
ParameterDirection.ReturnValue;
try
{
//SqlDataReader reder = cmd.ExecuteReader();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
var ss = reader[0];
var bb = reader[1];
}
maxCount = Convert.ToInt32(cmd.Parameters["@Result"].Value);
}
catch (Exception ex)
{
}
我得到 Exeption Message = A RETURN statement with a return value cannot be used in this context。当我删除 RETURN @MaxCount 一切正常但我没有得到 MaxCount