BeginLoadData EndLoadData method 提高填充效率 一般用于typed DataSet中
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
st.Start();
SqlConnection con = new SqlConnection("server=(local);database=northwind;user id = sa;pwd = avego");
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from products";
cmd.CommandType = System.Data.CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
Northwind northwind = new Northwind();
//this.Northwind.Products.EnforceConstraints = false;
// northwind.Products.BeginLoadData();
adapter.Fill(northwind.Products);
// northwind.Products.EndLoadData();
this.GridView1.DataSource = northwind.Products .DefaultView;
this.GridView1.DataBind();
this.TextBox1.Text = northwind.Products[5].ProductName;
this.TextBox2.Text = northwind.Products[5].CategoryID.ToString ();
con.Close();
st.Stop();
Response.Write("st=" + st.Elapsed);
}
浙公网安备 33010602011771号