I have a dynamic list object
that i want to BulkInsert
into my DB
, i was using the old OracleBulkCopy
method from another lib, but i can't use that lib anymore and on the new lib i don't have this method.
New lib : using Oracle.ManagedDataAccess.Client;
Old lib : Oracle.DataAccess.Client
Does anyone know a easy way to do the Bulk
without creating lists or arrays to do it?
The Oracle.ManagedDataAccess.Client
lib doesn't yet support BulkCopy.
You can compare functionality from both libs in the folowing link: Oracle Managed Driver Comparison
Related Question
Another option would be to use Array Binding.
Example:
using Oracle.ManagedDataAccess.Client;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string connString = "Data Source=xyz; user id=**; password=**";
using (var con = new OracleConnection(connString))
{
con.Open();
int[] foos = new int[3] { 1, 2, 3 };
string[] bars = new string[3] { "A", "B", "C" };
OracleParameter pFoo = new OracleParameter();
pFoo.OracleDbType = OracleDbType.Int32;
pFoo.Value = foos;
OracleParameter pBar = new OracleParameter();
pBar.OracleDbType = OracleDbType.Varchar2;
pBar.Value = bars;
// create command and set properties
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "insert into test (foo, bar) values (:1, :2)";
cmd.ArrayBindCount = foos.Length;
cmd.Parameters.Add(pFoo);
cmd.Parameters.Add(pBar);
cmd.ExecuteNonQuery();
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With