forked from billgraziano/CsvDataReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerShell Import.ps1
More file actions
29 lines (22 loc) · 1.63 KB
/
PowerShell Import.ps1
File metadata and controls
29 lines (22 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cls
$ConnectionString = "Data Source=L80\SQL2012;Initial Catalog=tempdb;Integrated Security=True;"
#$ErrorActionPreference = "Stop"
[System.Reflection.Assembly]::LoadFrom(".\CsvDataReader\bin\Debug\CsvDataReader.dll")
$reader = New-Object SqlUtilities.CsvDataReader(".\CsvDataReaderTest\SimpleCsv.txt")
#while ($reader.Read())
#{
# $reader.GetValue(0);
#}
#
#$reader.Close();
#$reader.Dispose();
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $ConnectionString
$bulkCopy.DestinationTableName = "CsvDataReader"
$bulkCopy.BatchSize = 100000
$bulkCopy.BulkCopyTimeout = 0
# Sample syntax if column mapping is needed
# Columns ARE CASE SENSITIVE!
# $bulkCopy.ColumnMappings.Add("PrimaryNumber", "PrimaryNumber") | Out-Null
$bulkCopy.WriteToServer($reader);
$reader.Close();
$reader.Dispose();