如何获取输出参数的值 ParameterDirection.Output
金蝶云社区-135xxxx7100
135xxxx7100
0人赞赏了该文章 830次浏览 未经作者许可,禁止转载编辑于2016年06月22日 15:26:28

我是要实现分页获取数据,在sql中(不是存储过程),我先获取总记录数,然后计算页数,通过输出参数获取计算后的值,同时也可以获取到查询出的数据,问题来了,通过对SqlParam设置ParameterDirection.Output并不能获取到输出的页数,微软自带的SqlParameter设置了就可以,为什么类似的SqlParam就不行呢,这种需求,我该怎么实现?

附上代码段:


string sql = "/*dialect*/\r\n" + " select @RowCount=count(1)" + sqlFrom + " if @PageIndex>@RowCount set @PageIndex=@RowCount" + " select top " + pageSize.ToString() + " *" + sqlFrom + " where t.RowIndex>" + pageSize.ToString() + "*(@PageIndex-1)" ;
SqlParam pPageIndex = new SqlParam("@PageIndex", KDDbType.Int32, pageIndex, ParameterDirection.InputOutput); SqlParam pRowCount = new SqlParam("@RowCount", KDDbType.Int32, 0, ParameterDirection.Output);
List pList = new List(); pList.Add(pPageIndex); pList.Add(pRowCount);
DataTable contractDataTable = DBUtils.ExecuteDataSet(context, sql, pList).Tables[0]; int rowCount = Convert.ToInt32(Math.Ceiling(((int)pRowCount.Value) * 1.0 / pageSize));