I am using IronPython to create a data array and I need to insert this array to MS SQL Server. The .Net class I'm using is SqlBulkCopy (part of System.Data.SqlClient).
I have found this StackOverflow article quite useful SqlBulkCopy from a list
However, since I'm only starting to learn python I'm having difficulties recreating this C# example with Python code.
Here's what I have so far
import clr
clr.AddReference('System.Data')
from System.Data import *
import clr
clr.AddReference('System')
from System import *
sqlDbConnection = SqlClient.SqlConnection("<my-db-connection-string>")
sqlDbConnection.Open()
myDataArray = [
[Byte(7), Byte(8), Int32(1), Byte(15), Byte(12), Single(0.34324)],
[Byte(5), Byte(1), Int32(2), Byte(11), Byte(10), Single(0.77362)],
[Byte(9), Byte(2), Int32(3), Byte(12), Byte(9), Single(0.93394)]]
sqlDbConnection.Close()
The idea is to generate a large data array (say > 1 Million rows) and import it to my table using bulk copy method. I would really appreciate if anyone could shed a light on this and explain how I could tackle this and how I can make use of all the options that come with the bulk copy class. SqlBulkCopy msdn reference
I have been looking for useful examples in Python but did not find any so far...
Much appreciated