I want to transfer a large amount of data from F# to an SQL table. Basically my F# code creates a matrix of three columns (UserID, ProductID and price) and N li
This should get you started (and reference the documentation for more information about SqlBulkCopy):
//you must reference System.Data and System.Xml
open System.Data
open System.Data.SqlClient
let bulkLoadUserPurchases (conn:SqlConnection) (userPurchases: list) =
use sbc = new SqlBulkCopy(conn, SqlBulkCopyOptions.TableLock, null, BatchSize=500, BulkCopyTimeout=1200, DestinationTableName="YOUR_TABLE_NAME_HERE")
sbc.WriteToServer(
let dt = new DataTable()
["UserID", typeof
"ProductID", typeof
"Price", typeof]
|> List.iter (dt.Columns.Add>>ignore)
for userPurchase in userPurchases do
let userId, productId, price = userPurchase
let dr = dt.NewRow()
dr.["UserID"] <- userId
dr.["ProductID"] <- productId
dr.["Price"] <- price
dt.Rows.Add(dr)
dt)