using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillGridViewByCallback();
}
}
public void FillGridViewByCallback()
{
string connString = "Database=Northwind;Server=.;User Id=sa;Password=;Asynchronous Processing=true;MultipleActiveResultSets=True";
SqlConnection connNorthwind = new SqlConnection(connString);
SqlCommand commProducts = new SqlCommand("select * from Products", connNorthwind);
SqlCommand ordersComm = new SqlCommand("select * from orders", connNorthwind);
connNorthwind.Open();
commProducts.BeginExecuteReader(new AsyncCallback(productsCallbackMethod), commProducts, CommandBehavior.CloseConnection);
ordersComm.BeginExecuteReader(new AsyncCallback(ordersCallbackMethod), ordersComm, CommandBehavior.CloseConnection);
connNorthwind.Close();
}
public void productsCallbackMethod(IAsyncResult ar)
{
SqlCommand commProducts = ar.AsyncState as SqlCommand;
SqlDataReader productsReader = commProducts.EndExecuteReader(ar);
gvProducts.DataSource = productsReader;
gvProducts.DataBind();
}
public void ordersCallbackMethod(IAsyncResult ar)
{
SqlCommand commOrders = ar.AsyncState as SqlCommand;
SqlDataReader ordersReader = commOrders.EndExecuteReader(ar);
gvOrders.DataSource = ordersReader;
gvOrders.DataBind();
}
}
程序执行无任何显示,并出现异步操作已完成。请大虾们帮忙,感谢!
[此贴子已经被作者于2007-10-4 0:14:58编辑过]