Skip to Main Content

Bulk insert with Unicode fields

User_0J77AMar 30 2021

Hi there,
I'm using the OracleBulkCopy functionality to insert data into a table, but am running into issues with Unicode fields.
I am making use of the latest version of the Oracle.ManagedDataAccess library (v.19.11.0), targeting the full .NET Framework (4.7.1).
My test table was created using the following statement:

CREATE TABLE TestTable 
(
   StringValue1 VARCHAR2(100),
   StringValue2 NVARCHAR2(100)
)

The C# code that inserts the data looks like this:

using (var bulkCopy = new OracleBulkCopy(connection))
{
   bulkCopy.DestinationTableName = "TestTable";
   var table = new DataTable("TestTable");
   table.Columns.Add("StringValue1", typeof(string));
   table.Columns.Add("StringValue2", typeof(string));
   var row = table.NewRow();
   row["StringValue1"] = "ABC";
   row["StringValue2"] = "ABC";
   table.Rows.Add(row);
   bulkCopy.WriteToServer(table);
}

The code executes without any errors. When selecting the results from the table I see the following:
Results.png
As you can see from the result, the NVARCHAR2 field was not populated correctly. Is this a bug in the library or is there some additional logic required for Unicode fields?
Any help would be be appreciated!

This post has been answered by Alex Keh-Oracle on Mar 30 2021
Jump to Answer
Comments
Post Details
Added on Mar 30 2021
6 comments
161 views