Bulk Copy Insert


Snippet Details

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

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