c# – Encoding issue when unloading from MySQL in C #

Question:

good day

I ask for help. The problem is as follows: There is a database in MySQL, MySQL encoding is cp1251, I unload in C # using MySqlConnection and put it in the dataGridView, but Russian characters are not recognized when unloading, tell me what to do?

I have already tried to specify the encoding in the connection string:

string conString = "Database=; Data Source=; User Id=; Password=; CharSet=utf8";

and a request after establishing a connection

MySqlCommand command = new MySqlCommand("SET character_set_results = \"utf8\",character_set_client = \"utf8\",character_set_connection = \"utf8\";", sql);

and the same request

"Set NAMES cp1251"

Tell me what other options you can try (there is no access to the server's ini files)?

Answer:

There was a similar problem, we solved it like this

SELECT CONVERT(CAST(t.ColumnName as BINARY) USING utf8) FROM t

You can read more details here – http://nicj.net/mysql-converting-an-incorrect-latin1-column-to-utf8/

Scroll to Top