59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace SDA.DataProvider.MSSQLWrappers
|
|
{
|
|
/// <summary>
|
|
/// Microsoft SQL Server alapú bulk insert implementáció.
|
|
/// </summary>
|
|
public class MSSQLBulkAdapter : SDABulkAdapter
|
|
{
|
|
private readonly SqlBulkCopy bulkCopy;
|
|
|
|
/// <summary>
|
|
/// Létrehoz egy Microsoft SQL Server specifikus bulk adapter példányt.
|
|
/// </summary>
|
|
/// <param name="bulkCopy">Egy SQL Server SqlBulkCopy példány, a
|
|
/// tényleges bulk implementáció.</param>
|
|
/// <exception cref="ArgumentNullException">Ha a kapott paraméter null.
|
|
/// </exception>
|
|
internal MSSQLBulkAdapter([NotNull] SqlBulkCopy bulkCopy)
|
|
{
|
|
if (bulkCopy == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(bulkCopy));
|
|
}
|
|
this.bulkCopy = bulkCopy;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void BulkInsert(DataTable source)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(source.TableName))
|
|
{
|
|
throw new ArgumentException("TableName property must be set to the target table name", nameof(source));
|
|
}
|
|
|
|
if (source.Columns.Count == 0)
|
|
{
|
|
throw new ArgumentException("should contain at least 1 column to bulk insert", nameof(source));
|
|
}
|
|
|
|
if (source.Rows.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
bulkCopy.DestinationTableName = source.TableName;
|
|
bulkCopy.WriteToServer(source);
|
|
|
|
//bulkCopy.NotifyAfter = 1000;
|
|
//bulkCopy.SqlRowsCopied += (sender, args) =>
|
|
//{
|
|
|
|
//};
|
|
}
|
|
}
|
|
}
|