【发布时间】:2020-08-03 15:22:41
【问题描述】:
我从 SqlDataReader 加载 DataTable,然后将它数据绑定到数据网格。当我同步执行阅读器时,数据网格会正确加载。当我异步执行阅读器时,数据网格为空。这是代码。
同步 - 工作
async public Task<DataTable> GetDataTableAsync()
{
DataTable result = new DataTable();
await this.Conn.OpenAsync();
SqlDataReader reader = this.Comm.ExecuteReader();
result.Load(reader);
this.Conn.Close();
return result;
}
异步 - 不起作用
async public Task<DataTable> GetDataTableAsync()
{
DataTable result = new DataTable();
await this.Conn.OpenAsync();
SqlDataReader reader = await this.Comm.ExecuteReaderAsync();
result.Load(reader);
this.Conn.Close();
return result;
}
DataTable 在这两种情况下完全一样。
项目是经典的 ASP.NET,数据网格是 Telerik RadGrid
【问题讨论】:
-
什么是“this.Comm”?
-
this.Comm 是带有 sql 文本和参数的 SqlCommand 实例
标签: asp.net asynchronous data-binding datatable