public async Task <DataTable> GetDataTableAsync(System.Data.Common.DbCommand data_command, string tableName = null)
{
TaskCompletionSource <DataTable> source = new TaskCompletionSource <DataTable>();
var resultTable = new DataTable(tableName ?? data_command.CommandText);
data_command.Connection = new SqlConnection(constring);
DbDataReader dataReader = null;
try
{
await data_command.Connection.OpenAsync();
dataReader = await data_command.ExecuteReaderAsync(CommandBehavior.Default);
resultTable.Load(dataReader);
source.SetResult(resultTable);
}
catch (Exception ex)
{
source.SetException(ex);
}
finally
{
if (dataReader != null)
{
dataReader.Close();
}
data_command.Connection.Close();
}
return(resultTable);
}