Error: Registering ? instead of special character only using browser

Asked

Viewed 934 times

4

I am having a problem at the time of saving the data in my ORACLE database.

When using my application to fill in the fields and register a string, the special characters as accents for example are replaced by a ? in the database

The detail is that if I take the same query and do by SQL DEVELOPER it usually registers any special character.

My application is done in C#, with the pages using Razor (cshtml). The html charset is UTF-8.

I do not know how to check the bank’s charset, because I am very beginner in ORACLE.

Ideas about what might be causing this?

Code in the application:

comand.CommandText = "UPDATE TB_EBITDA SET TXT_OBSERVACAO = '" + txt_observacao + "' WHERE COD_CONFIGURACAO = " + codigo + "";
dataReader = comand.ExecuteReader();
dataReader.Read();

Code generated, picked through debug and paste in SQL Developer:

UPDATE TB_EBITDA SET TXT_OBSERVACAO = 'Observacão' WHERE COD_CONFIGURACAO = 5
  • Please pass the code used to enter the data into the database?

  • I don’t know if it’s very relevant, but there you are. "Observation" I wrote without the same. But it records "Observac? o"

  • You are not using parameters to execute your command. The correct one would be yours CommandText have the parameter declaration and specify the Unicode in the parameter.

  • Can you give an example?

  • I’ll try to answer.

  • Wouldn’t that be a configuration of the bank itself? Because its command seems to be right. Have a look at this link(http://eltzti.wordpress.com/2011/06/13/configuracao-apex-oracle-xe-charactecterset/) and if possible make the changes.

Show 1 more comment

1 answer

2


Apparently the problem is the (lack of) parameterization of your sentence. Without this parameterization, nothing guarantees that you are executing a sentence adhering to the Unicode standard.

I would write your code as follows:

comand.CommandText = "UPDATE TB_EBITDA SET TXT_OBSERVACAO = :txt_observacao WHERE COD_CONFIGURACAO = " + codigo + "";

IDbDataParameter param = comand.CreateParameter()
param.DbType = DbType.AnsiString;
param.ParameterName = "txt_observacao";
param.Value = txt_observacao;

comand.Parameters.Add(param);
dataReader = comand.ExecuteReader();
dataReader.Read();
  • Thank you very much, your answer was the lever to get me a solution. Allow me to edit your answer and put the code that worked for me? So I mark yours as correct.

  • @Joaopaulo Yes, of course! Make yourself at home.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.