标签:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class Main : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int totalpage; List<StuInfo> List = new List<StuInfo>(); gv_stu.DataSource = GetStuInfo(10, 2, ‘ ‘, out totalpage); gv_stu.DataBind(); } public List<StuInfo> GetStuInfo(int pagesize,int currentpage,string condition,out int totalpage) { List<StuInfo> List = new List<StuInfo>(); //string sqlconstr = "Data Source=.;Initial Catalog=Example;User ID=sa;Password=123456"; string sqlconstr = "Data Source=.;Initial Catalog=Example;Integrated Security=true"; string sql = "proc_GetStuInfo"; SqlConnection con = new SqlConnection(sqlconstr); SqlCommand cmd = new SqlCommand(sql, con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); SqlParameter[] para = { new SqlParameter("@pagesize",pagesize), new SqlParameter("@currentpage",currentpage), new SqlParameter("@condition",condition), new SqlParameter("@pagesize",SqlDbType.Int) }; para[3].Direction = ParameterDirection.Output; cmd.Parameters.AddRange(para); { while(sdr.Read()) { StuInfo stu = new StuInfo(); stu.Stuid = sdr["stuid"].ToString(); stu.Stuname = sdr["stuname"].ToString(); stu.Age = Convert.ToInt32(sdr["age"]); stu.Address = sdr["address"].ToString(); List.Add(stu); } } con.Close(); totalpage =Convert.ToInt32(para[3].Value); return List; } }
标签:
原文地址:http://www.cnblogs.com/cylblogs/p/4944010.html