本文整理匯總了C#中System.Data.DataTable.WriteCsvAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.WriteCsvAsync方法的具體用法?C# DataTable.WriteCsvAsync怎麽用?C# DataTable.WriteCsvAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.WriteCsvAsync方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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
}
示例2: write_csv_async_returns_number_of_records_written
public async Task write_csv_async_returns_number_of_records_written()
{
using (var writer = new CsvWriter(new StringWriter()))
{
writer.WriteRecord("some", "record");
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
dataTable.Rows.Add("1", "2");
dataTable.Rows.Add("3", "4");
dataTable.Rows.Add("5", "6");
Assert.Equal(3, await dataTable.WriteCsvAsync(writer, false));
Assert.Equal(3, await dataTable.WriteCsvAsync(writer, true));
}
}
示例3: write_csv_async_works_with_large_data_table_input
public async Task write_csv_async_works_with_large_data_table_input()
{
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
for (var i = 0; i < 1000; ++i)
{
dataTable.Rows.Add("value0_" + i, "value1_" + i);
}
// write less than all available records
using (var writer = new CsvWriter(new StringWriter()))
{
Assert.Equal(913, await dataTable.WriteCsvAsync(writer, true, 913));
}
// write exactly available records
using (var writer = new CsvWriter(new StringWriter()))
{
Assert.Equal(1000, await dataTable.WriteCsvAsync(writer, true, 1000));
}
// attempt to write more than available records
using (var writer = new CsvWriter(new StringWriter()))
{
Assert.Equal(1000, await dataTable.WriteCsvAsync(writer, true, 1500));
}
}
示例4: write_csv_async_object_to_string_converter_converts_nulls_to_empty_string
public async Task write_csv_async_object_to_string_converter_converts_nulls_to_empty_string()
{
using (var stringWriter = new StringWriter())
using (var writer = new CsvWriter(stringWriter))
{
writer.NewLine = "<EOL>";
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
dataTable.Rows.Add("1", 2);
dataTable.Rows.Add(null, 4d);
dataTable.Rows.Add(5m, null);
Assert.Equal(3, await dataTable.WriteCsvAsync(writer));
Assert.Equal("First,Second<EOL>1,2<EOL>,4<EOL>5,<EOL>", stringWriter.ToString());
}
}
示例5: write_csv_async_uses_object_to_string_converter_to_convert_objects_in_data_row_to_string
public async Task write_csv_async_uses_object_to_string_converter_to_convert_objects_in_data_row_to_string()
{
using (var stringWriter = new StringWriter())
using (var writer = new CsvWriter(stringWriter))
{
writer.NewLine = "<EOL>";
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
dataTable.Rows.Add("1", 2);
dataTable.Rows.Add(3, 4d);
dataTable.Rows.Add(5m, 6f);
Assert.Equal(3, await dataTable.WriteCsvAsync(writer, true, null, o => o.ToString() + "_SUFFIX"));
Assert.Equal("First,Second<EOL>1_SUFFIX,2_SUFFIX<EOL>3_SUFFIX,4_SUFFIX<EOL>5_SUFFIX,6_SUFFIX<EOL>", stringWriter.ToString());
}
}
示例6: write_csv_async_stops_if_it_reaches_maximum_rows
public async Task write_csv_async_stops_if_it_reaches_maximum_rows()
{
using (var stringWriter = new StringWriter())
using (var writer = new CsvWriter(stringWriter))
{
writer.NewLine = "<EOL>";
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
dataTable.Rows.Add("1", "2");
dataTable.Rows.Add("3", "4");
dataTable.Rows.Add("5", "6");
Assert.Equal(2, await dataTable.WriteCsvAsync(writer, true, 2));
Assert.Equal("First,Second<EOL>1,2<EOL>3,4<EOL>", stringWriter.ToString());
}
}
示例7: write_csv_async_writes_all_rows_as_data_records
public async Task write_csv_async_writes_all_rows_as_data_records()
{
using (var stringWriter = new StringWriter())
using (var writer = new CsvWriter(stringWriter))
{
writer.NewLine = "<EOL>";
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
dataTable.Rows.Add("1", "2");
dataTable.Rows.Add("3", "4");
dataTable.Rows.Add("5", "6");
Assert.Equal(3, await dataTable.WriteCsvAsync(writer, true));
Assert.Equal("First,Second<EOL>1,2<EOL>3,4<EOL>5,6<EOL>", stringWriter.ToString());
}
}
示例8: write_csv_async_writes_a_header_record_based_on_data_table_column_names_if_requested
public async Task write_csv_async_writes_a_header_record_based_on_data_table_column_names_if_requested()
{
using (var stringWriter = new StringWriter())
using (var writer = new CsvWriter(stringWriter))
{
writer.NewLine = "<EOL>";
var dataTable = new DataTable();
dataTable.Columns.Add("First");
dataTable.Columns.Add("Second");
Assert.Equal(0, await dataTable.WriteCsvAsync(writer, true));
Assert.Equal("First,Second<EOL>", stringWriter.ToString());
}
}