Bulk Copy Insert


Snippet Details

Shortcut
blk
Description
Skeleton for creating bulk insert method
Language
csharp
Types
Expansion
Author
Mike Cofoed
Upload on
14-2-2014 00:12:40
Downloads
2754

Declarations

ID ToolTip Default
FunctionName FunctionName
TableType TableType
DestinationTable DestinationTable
BatchSize 1000
Timeout 600
BulkCopy BulkCopy

Code Output

        /// <summary>
///
/// </summary>
/// <param name="tbl"></param>
public void $FunctionName$($TableType$ tbl) {
	if (tbl == null) { throw new ArgumentNullException("tbl"); }
	using (SqlBulkCopy $BulkCopy$ = new SqlBulkCopy(this.ConnectionString, SqlBulkCopyOptions.Default)) {
		$BulkCopy$.DestinationTableName = "$DestinationTable$";
		$BulkCopy$.BatchSize = $BatchSize$;
		$BulkCopy$.BulkCopyTimeout = $Timeout$;
		foreach (DataColumn col in tbl.Columns) {
			$BulkCopy$.ColumnMappings.Add(col.ColumnName, col.Caption);
		}
		$BulkCopy$.WriteToServer(tbl);
	}
}
    

Download Add to .VSIX Package


comments powered by Disqus

Extension Package

No snippets are added


Languages