Search code examples
c#unicodeoracle11gnvarchar

enterprise library dbcommand AddInParameter method for Oracle


My question is very similar to this question - Addin parameter for Oracle except that i'm using Oracle 11g. The datbase has two different charactersets for VARCHAR(Western European) and NVARCHAR(Unicode) datatypes.

db.AddInParameter(cmd, "nationalColumn", DbType.String, "高野")

National characterset in the database is unicode and so NVARCHAR columns are able to hold these characters.

My question is how do i tell db.AddInParameter function that the parameter i'm adding is a NVARCHAR and not a VARCHAR which it seems to be assuming by default.

Adding to this - I'm using System.Data.OracleClient to connect to the database


Solution

  • I'm answering my own question as i spent a week figuring it out. The System.Data namespace doesn't understand that the column it's handling is a national column unless it is specified explicitly as OracleType.Nvarchar.

    To resolve the situation above, I had to override the AddInParameter function to add a switch case that checks if the input DBType is a String and map it to a OracleType.NVarchar.

    HTH