You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
using System;
|
|
using System.Data;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class DataTableExtensions
|
|
{
|
|
public static DataTable SetHeaders(this DataTable dataTable, params string[] headers)
|
|
{
|
|
if (dataTable is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(dataTable));
|
|
}
|
|
foreach (var item in headers)
|
|
{
|
|
dataTable.Columns.Add(new DataColumn(item));
|
|
}
|
|
return dataTable;
|
|
}
|
|
|
|
public static DataTable Add(this DataSet dataSet, string tableName, params string[] headers)
|
|
{
|
|
if (dataSet is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(dataSet));
|
|
}
|
|
if (tableName is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(tableName));
|
|
}
|
|
var dataTable = dataSet.Tables.Add();
|
|
dataTable.TableName = tableName;
|
|
return dataTable.SetHeaders(headers);
|
|
}
|
|
}
|
|
} |