/////调用存储过程
public pageList<MM> getshuju( int pageindex,int pagesize,string name )
{
if (string.IsNullOrWhiteSpace(name))
name = "";
SqlCommand cmd = new SqlCommand("stu_ProcedureName", con);
cmd.CommandType = CommandType.StoredProcedure;//执行执行的是存储过程
SqlParameter pageidnexs = new SqlParameter("@pageindex", pageindex);
SqlParameter pagesizes = new SqlParameter("@pageSize", pagesize);
SqlParameter names = new SqlParameter("@name", name);
SqlParameter counts = new SqlParameter("@count", SqlDbType.Int);
counts.Direction = ParameterDirection.Output;//输出参数
cmd.Parameters.Add(pageidnexs);
cmd.Parameters.Add(pagesizes);
cmd.Parameters.Add(names);
cmd.Parameters.Add(counts);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable tb = new DataTable();
da.Fill(tb);
var data = JsonConvert.SerializeObject(tb);
var data2 = JsonConvert.DeserializeObject<List<MM>>(data);
pageList<MM> lsit= new pageList<MM>();
lsit.count = Convert.ToInt32(counts.Value);
lsit.pageindex = pageindex;
lsit.pagesize = pagesize;
lsit.shuju = data2;
return lsit;
}
嵌套类
public class MM
{
public int newid { get; set; }
public int id { get; set; }
public string Names { get; set; }
public int age { get; set; }
public string adress { get; set; }
}
public class pageList<MM>
{
public int pageindex { get; set; }
public int pagesize { get; set; }
public int count { get; set; }
public List<MM> shuju{get;set;}
}