本文整理匯總了C#中System.Data.DataTable.FillAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.FillAsync方法的具體用法?C# DataTable.FillAsync怎麽用?C# DataTable.FillAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.FillAsync方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: fill_data_table_async_works_with_large_csv_input
public async Task fill_data_table_async_works_with_large_csv_input()
{
var csv = string.Empty;
using (var stringWriter = new StringWriter())
using (var writer = new CsvWriter(stringWriter))
{
writer.WriteRecord("Header1", "Header2");
for (var i = 0; i < 1000; ++i)
{
writer.WriteRecord("value0_" + i, "value1_" + i);
}
writer.Flush();
csv = stringWriter.ToString();
}
// read less than all available records
using (var reader = CsvReader.FromCsvString(csv))
{
var table = new DataTable();
reader.ReadHeaderRecord();
Assert.Equal(913, await table.FillAsync(reader, 913));
Assert.Equal(913, table.Rows.Count);
Assert.True(reader.HasMoreRecords);
}
// read exactly available records
using (var reader = CsvReader.FromCsvString(csv))
{
var table = new DataTable();
reader.ReadHeaderRecord();
Assert.Equal(1000, await table.FillAsync(reader, 1000));
Assert.Equal(1000, table.Rows.Count);
Assert.False(reader.HasMoreRecords);
}
// attempt to read more than available records
using (var reader = CsvReader.FromCsvString(csv))
{
var table = new DataTable();
reader.ReadHeaderRecord();
Assert.Equal(1000, await table.FillAsync(reader, 1500));
Assert.Equal(1000, table.Rows.Count);
Assert.False(reader.HasMoreRecords);
}
}
示例2: FillDataTableFromCSVFileThenWriteSomeToStringAsynchronously
private async static Task FillDataTableFromCSVFileThenWriteSomeToStringAsynchronously()
{
#region FillDataTableFromCSVFileThenWriteSomeToStringAsynchronously
var table = new DataTable();
using (var streamReader = new StreamReader("PlanetaryData.csv"))
using (var reader = new CsvReader(streamReader))
{
await reader.ReadHeaderRecordAsync();
await table.FillAsync(reader);
}
using (var stringWriter = new StringWriter())
{
using (var writer = new CsvWriter(stringWriter))
{
await table.WriteCsvAsync(writer, false, 5);
}
Console.WriteLine("CSV: {0}", stringWriter);
}
#endregion
}
示例3: fill_data_table_async_stops_if_it_reaches_maximum_records
public async Task fill_data_table_async_stops_if_it_reaches_maximum_records()
{
var table = new DataTable();
var csv = @"Header1,Header2
1,2
3,4
5,6
7,8";
using (var reader = CsvReader.FromCsvString(csv))
{
reader.ReadHeaderRecord();
Assert.Equal(3, await table.FillAsync(reader, 3));
Assert.Equal(3, table.Rows.Count);
Assert.True(reader.HasMoreRecords);
}
}
示例4: fill_data_table_async_stops_short_of_maximum_records_if_it_runs_out_of_data
public async Task fill_data_table_async_stops_short_of_maximum_records_if_it_runs_out_of_data()
{
var table = new DataTable();
var csv = @"Header1,Header2
1,2
3,4";
using (var reader = CsvReader.FromCsvString(csv))
{
reader.ReadHeaderRecord();
Assert.Equal(2, await table.FillAsync(reader, 10));
Assert.Equal(2, table.Rows.Count);
}
}
示例5: fill_data_table_async_uses_header_record_if_columns_are_not_specified
public async Task fill_data_table_async_uses_header_record_if_columns_are_not_specified()
{
var table = new DataTable();
var csv = @"Header1,Header2
1,2";
using (var reader = CsvReader.FromCsvString(csv))
{
reader.ReadHeaderRecord();
Assert.Equal(1, await table.FillAsync(reader));
Assert.Equal(1, table.Rows.Count);
Assert.Equal("Header1", table.Columns[0].ColumnName);
Assert.Equal("Header2", table.Columns[1].ColumnName);
Assert.Equal("1", table.Rows[0][0]);
Assert.Equal("2", table.Rows[0][1]);
}
}
示例6: DataTable
public async Task fill_data_table_async_throws_if_the_number_of_values_in_a_record_exceeds_the_number_of_columns_in_the_data_table()
{
var table = new DataTable();
table.Columns.Add("First");
table.Columns.Add("Second");
using (var reader = CsvReader.FromCsvString("first,second,third"))
{
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => table.FillAsync(reader));
Assert.Equal("DataTable has 2 columns, but a DataRecord had 3. The number of columns in the DataTable must match or exceed the number of values in each DataRecord.", ex.Message);
}
}
示例7: FillDataTableFromCSVFileAsynchronously
private static async Task FillDataTableFromCSVFileAsynchronously()
{
#region FillDataTableFromCSVFileAsynchronously
var table = new DataTable();
using (var streamReader = new StreamReader("PlanetaryData.csv"))
using (var reader = new CsvReader(streamReader))
{
await reader.ReadHeaderRecordAsync();
await table.FillAsync(reader);
}
Console.WriteLine("Table contains {0} rows.", table.Rows.Count);
#endregion
}