I have the following function in a .NET Core 2.0 app.
public DataTable CallDb(string connStr, string sql)
{
var dt = new DataTable();
var da = new Sq
Although the initial call to ExecuteReaderAsync()
will not block in this case, dt.Load(reader)
probably does the equivalent of reader.Read()
rather than await reader.ReadAsync()
, and may block the calling thread while retrieving rows.
If you do need a DataTable
for use with an external API, or because you don't know the field definitions in advance, but require fully asynchronous behaviour, you might be better off to use your own code to construct a DataTable
, add the required columns e.g. based on reader.GetName()
and reader.GetFieldType()
, and then populate it with rows in a loop using await reader.ReadAsync()
and dt.Rows.Add()
.