1
In my application I am having trouble fetching the data in the Postgresql database, the words with accentuations when retrieved from the database and dealing in DataReader
are coming badly formatted as in the image below.
- In the database with correct format
- Being read in the
DataReader
The Encoding of the bank is in UTF8 and the Character type is in Portuguese_brazil.1252 if it helps.
I’m reading the data as follows:
var command = new NpgsqlCommand("Select * from Empresa", con);
con.Open();
NpgsqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
Empresa e = new Empresa();
e.IdEmpresa = Convert.ToInt32(dr["id_empresa"]);
e.NomeFantasia = dr["nome_fantasia"].ToString();
}
Follow the image to demonstrate the language better than this database of mine:
Show how you are reading the data. I don’t quite understand if you are using UTF8 or CP1252, they are different things. Maybe the problem is there.
– Maniero
right, I put + details answering my question to put the image
– ErickV
You must [Dit] the question and not answer it with an addition.
– Maniero
How is the connection? It configures the charset? Have you tried using
UTF8Encoding.UTF8.GetString()
or something like that?– Maniero
Pãs is clearly UTF-8 being displayed in 1252. Either you convert to 1252 to display, or use an output that shows UTF-8.
– Bacco
Another example: Action in UTF-8 is Açà in win1252 (or even ISO-8859-1).
– Bacco
how can I set the charset or convert it to 1252 to show the correct accents? I’m new to C#.
– ErickV