Stopwatch类验证LINQ分页之强大

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
    
namespace stopwatch
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Stopwatch sp = new Stopwatch();
            sp.Start();
            GridView1.DataSource = dt();
            GridView1.DataBind();
            GridView1.DataSource = null;
            GridView1.DataBind();
            sp.Stop();
            TimeSpan ts = sp.Elapsed;
            Response.Write(ts);
            Response.Write("<br/>");
            sp.Reset();
            sp.Start();
            IDataReader dd = dr();
            GridView1.DataSource = dd;
            GridView1.DataSource = null;
            GridView1.DataBind();
            GridView1.DataBind();
            dd.Close();
            sp.Stop();
            ts = sp.Elapsed;
            Response.Write(ts);
            Response.Write("<br/>");
            sp.Restart();
            GridView1.DataSource = ss();
            GridView1.DataSource = null;
            GridView1.DataBind();
            GridView1.DataBind();
            sp.Stop();
            ts = sp.Elapsed;
            Response.Write(ts);
    
            Response.Write("<br/>");
            sp.Restart();
            GridView1.DataSource = dt2();
            GridView1.DataSource = null;
            GridView1.DataBind();
            GridView1.DataBind();
            sp.Stop();
            ts = sp.Elapsed;
            Response.Write(ts);
                
        }
    
        public DataTable dt()
        {
            string str = ConfigurationManager.ConnectionStrings[1].ToString();
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from (select   * ,ROW_NUMBER() over(order by name desc) as ff    from www ) aa where  ff between 40  and  150", con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            con.Close();
            cmd.Dispose();
            return dt;
    
        }
    
        public IDataReader dr()
        {
            string str = ConfigurationManager.ConnectionStrings[1].ToString();
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from (select   * ,ROW_NUMBER() over(order by name desc) as ff    from www ) aa where  ff between 40  and  150", con);
            SqlDataReader dr = cmd.ExecuteReader();
            return dr;
        }
    
        xxDataContext cc = new xxDataContext();
    
        public List<www> ss()
        {
            var strLinq = cc.www.Where(p => p.age >= 40 & p.age <= 50);
            return strLinq.ToList();
    
        }
    
        public DataTable dt2()
        {
            string str = ConfigurationManager.ConnectionStrings[1].ToString();
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd = new SqlCommand("ff", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            con.Close();
            cmd.Dispose();
            return dt;
    
        }
    
    
    }
}


知识共享许可协议
《Stopwatch类验证LINQ分页之强大》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

1 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     163.33ms