Created
August 17, 2014 15:25
-
-
Save pstephens/3bcd5690186a8245204d to your computer and use it in GitHub Desktop.
Fun with F# and bulk copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fun with F# and bulk copy | |
open System.Configuration | |
open System.Data | |
open System.Data.SqlClient | |
let getOpenConnection () = | |
let cn = new SqlConnection(ConfigurationManager.ConnectionStrings.["TdsScratch"].ConnectionString) | |
cn.Open () | |
cn | |
[<EntryPoint>] | |
let main argv = | |
let tbl = new DataTable() | |
let fk1 = tbl.Columns.Add("FK1", typedefof<int>) | |
let fk2 = tbl.Columns.Add("FK2", typedefof<int>) | |
let successful = tbl.Columns.Add("Successful", typedefof<bool>) | |
use cn = getOpenConnection () | |
use bulkcopy = new SqlBulkCopy(cn, SqlBulkCopyOptions.TableLock, null) | |
bulkcopy.DestinationTableName <- "TheTable" | |
bulkcopy.ColumnMappings.Add("FK1", "FK1") |> ignore | |
bulkcopy.ColumnMappings.Add("FK2", "FK2") |> ignore | |
bulkcopy.ColumnMappings.Add("Successful", "Successful") |> ignore | |
tbl.Rows.Add(1, 2, true) |> ignore | |
bulkcopy.WriteToServer(tbl) | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment