| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 303 人关注过本帖
标题:ado.net使用回调方式处理异步进程,到底哪里出错了?
收藏  订阅  推荐  打印 
ruihua
Rank: 3Rank: 3
等级:中级会员
威望:1
帖子:232
积分:2470
注册:2006-2-21
ado.net使用回调方式处理异步进程,到底哪里出错了?

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编辑过]

搜索更多相关主题的帖子: using  System  ado  回调  异步  
2007-10-4 00:13
bygg
Rank: 12Rank: 12Rank: 12
来自:乖乖的心中
等级:版主
威望:170
帖子:9765
积分:97351
注册:2006-10-23

commProducts.BeginExecuteReader(new AsyncCallback(productsCallbackMethod), commProducts, CommandBehavior.CloseConnection);

public void productsCallbackMethod(IAsyncResult ar)
上面没有参数,下面有?

绑定数据用DataSet吧

一个天才顶不上十个笨蛋!
书山有路勤为径,学海无涯友相伴。
我的E-mail:mylover624@yahoo.com.cn
2007-10-4 18:45
ruihua
Rank: 3Rank: 3
等级:中级会员
威望:1
帖子:232
积分:2470
注册:2006-2-21

SqlDataReader也可以用作数据源的

2007-10-8 10:43
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.068279 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved