I'm trying to convert some code that uses NReco.Data to async version of ExecuteReader (ExecuteReaderAsync) but the methods requires many parameters. Any ideas ?
This is the working code with no-async version of ExecuteReader is:
System.Data.DataSet ds = nreco_DbDataAdapter.Select(sql_query).ExecuteReader(
(rdr) =>
{
System.Data.DataSet ds = new System.Data.DataSet();
ds.Tables.Add(new NReco.Data.DataReaderResult(rdr).ToDataTable());
rdr.NextResult();
ds.Tables.Add(new NReco.Data.DataReaderResult(rdr).ToDataTable());
return ds;
}
);
Not sure what paremeters I need to pass
In fact usage of ExecuteReaderAsync
is pretty the same as ExecuteReader
and the only difference is that 'read' handler should be async -- something like that:
System.Data.DataSet ds = await nreco_DbDataAdapter.Select(sql_query).ExecuteReaderAsync(
async (rdr, cancel) => {
System.Data.DataSet ds = new System.Data.DataSet();
ds.Tables.Add(await (new NReco.Data.DataReaderResult(rdr)).ToDataTableAsync(cancel));
rdr.NextResult();
ds.Tables.Add(await (new NReco.Data.DataReaderResult(rdr)).ToDataTableAsync(cancel));
return ds;
}, cancellationToken
);
This code should be in async method. If you don't have 'cancellationToken' here you can specify CancellationToken.None
.