sqlserver中定义好分页的存储过程,怎么使用存储过程查询?

2025-01-21 15:47:11
推荐回答(1个)
回答1:

试试:

private DataTable GetDataByPageProc(String TableName, String Primarykey, String FieldsName, String ByWHERE
, String ByOrder, int PageSize, int PageIndex, ref int RecordCount, ref int PageCount)
{
SqlConnection cn = new SqlConnection(Function.ConnectionString);
String sql = "exec P_SlipPage @TableName=@a,@Primarykey=@b,@FieldsName=@c,@ByWHERE=@d ,@ByOrder=@e ,@PageSize=@f ,@PageIndex=@g ,@RecordCount=@h ,@PageCount =@i";
using (SqlDataAdapter da = new SqlDataAdapter(sql, cn))
{
da.SelectCommand.Parameters.AddWithValue("@a", TableName);
da.SelectCommand.Parameters.AddWithValue("@b", Primarykey);
da.SelectCommand.Parameters.AddWithValue("@c", FieldsName);
da.SelectCommand.Parameters.AddWithValue("@d", ByWHERE);
da.SelectCommand.Parameters.AddWithValue("@e", ByOrder);
da.SelectCommand.Parameters.AddWithValue("@f", PageSize);
da.SelectCommand.Parameters.AddWithValue("@g", PageIndex);
da.SelectCommand.Parameters.AddWithValue("@h", RecordCount);
da.SelectCommand.Parameters.AddWithValue("@i", PageCount);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}