DataReader UTF-8

0

Quick Problem: I have a DropDownList that contains data with different special characters (',', ç ...) and I have to pass the DropDownList.SelectedItem.Text to a OracleComand cmd to then pass the cmd to OracleDataReader dr . The problem is that the dr does not interpret special characters, and when executing the query it returns 0 rows because it does not interpret the special characters.

How can I change the Encode of dr so that if I read those characters?

    
asked by Geraniego 03.05.2017 в 13:19
source

3 answers

1

Finally I discovered what my problem was:

I was using System.Data.OracleClient as Data Access Library, when I changed it to Oracle.DataAccess.Client It already works. Sorry for wasting your time

    
answered by 03.05.2017 / 15:50
source
1

You do not have to change the encode of the dr, but the one of the string that is happening to you. With this code you would pass UTF8 to unicode string. The final string is the one you should pass to the dr:

var dbEnc = Encoding.UTF8;
var uniEnc = Encoding.Unicode;
byte[] dbBytes = dbEnc.GetBytes(DropDownList.SelectedItem.Text);
byte[] uniBytes = Encoding.Convert(dbEnc, uniEnc, dbBytes);
string mensajeAPasarAlDr = uniEnc.GetString(uniBytes);
    
answered by 03.05.2017 в 14:07
0

When using System.Data.OracleClient I do not know if in the connection string you had this: Unicode=True , if the problem is the conversion from Unicode to UTF-8. This value causes calls from the client to use:

  

Specifies whether the .NET Framework Data Provider for Oracle uses UTF16 mode API calls

In msdn it indicates that the default value is False .

Even so, it is recommended to use the Oracle client libraries because they provide better performance and because the MS library was obsolete from .NET 4.0.

    
answered by 05.05.2017 в 15:39