[WebMethod]
public string GetJqueryPagerList(int curPage, int pageSize)
{
StringBuilder sb = new StringBuilder();
List<SimpleClass> list = new List<SimpleClass>();
SimpleClass simple = null;
int pageSum = 0, rowCount = 0;
string pageListStr = "";
using (SqlConnection conn = GetConnection())
{
SqlCommand cmd = new SqlCommand("ZW_PD_Test", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] paras = {
new SqlParameter("@curPage",curPage),
new SqlParameter("@pageSize",pageSize),
new SqlParameter("@pageSum",0),
new SqlParameter("@count",0)
};
paras[2].Direction = ParameterDirection.Output;
paras[3].Direction = ParameterDirection.Output;
cmd.Parameters.AddRange(paras);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
simple = new SimpleClass();
simple.MyProperty = sdr[0].ToString();
simple.MyProperty2 = sdr[1].ToString();
simple.MyProperty3 = sdr[2].ToString();
list.Add(simple);
}
sdr.Close();
sdr.Dispose();
pageSum = Convert.ToInt32(cmd.Parameters["@pageSum"].Value);
rowCount = Convert.ToInt32(cmd.Parameters["@count"].Value);
}
pageListStr = new JavaScriptSerializer().Serialize(list);
sb.Append("{\"pager\":{\"pageSum\":" + pageSum + ",\"rowCount\":" + rowCount + ",\"list\":" + pageListStr + "}}");
return sb.ToString();
}
当使用SqlDataReader对象后,如果要访问SqlCommand对象中的参数时,需要先将SqlDataReader对象关闭并释放掉!