Pregunta

I'm trying to populate a table with Chinese characters using a C# console program. The characters are perfectly preserved in the C# string, but when I want to execute the query with:

cmd.ExecuteNonQuery();

It basically creates a conversion problem. I have been looking around on the net and found out that it has to do with the console encoding. So I tried changing it this but it doesn't work.

Console.InputEncoding = Encoding.UTF8;
Console.OutputEncoding = Encoding.UTF8;

Query before execution:

INSERT INTO Sentences (cat, q, a)
VALUES ('English -> Chinese; HSK level 1; limited 1;       part 1','He caught a cold. ;;;  tā gǎn mào le。','他感冒了。')

INSERT in table:

English -> Chinese; HSK level 1; limited 1; part 1
He caught a cold. ;;; ta gan mào le?
?????

Direct query in phpmyadmin gives the desired result, so it's not a table encoding issue.

¿Fue útil?

Solución

I fixed it by adding "Charset=utf8;" to my connection string. Got the answer from THIS thread .

Otros consejos

Your query should have N before all string literals to make them unicode:

INSERT INTO Sentences (cat, q, a) VALUES (N'English -> Chinese; HSK level 1; limited 1; part 1',N'He caught a cold. ;;;  tā gǎn mào le。',N'他感冒了。')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top