Hi everyone!
Ok, so I have the following problem. I have a Winform with a dropdown list displaying every currency code in the world and if a user selects it the symbol displays next to the box. The symbols is a special character for most of the currencies. When displaying the currency next to the box there is no problem as it is a hard coded string. However, from this list the user will select his country currency and the currency code and the symbol is saved to the database. When I look at the database some of the special character currencies are saved as "?".... Throughout the rest of the application the symbol is not hard coded as it should retrieve the symbol from the database, but now when it should show [Symbol]100 .... it shows ?100 for example.
How do I save the symbol so it would be retrieved the way it should?
Hope you understand the question and know how to fix this!
Regards,
Chris
解决方案The first thing to check is the column format you are storing the symbol into - it should be NVARCHAR not VARCHAR as the former is Unicode and the latter is not (assuming you have MySQL 5 or above)
Then, there is the transfer of data into the column: if you are concatenating strings to form your SQL statement then you need to prefix the string constant with "N" to indicate that it is already National Character Set data:
INSERT INTO MyTable (currency) VALUES (N'£')
If you do it via parameterized queries (as you definitely should be anyway to avoid SQL Injection Attacks) then that is handled by the system automatically.
Reading out should be no problem: once you have got it in it should "just work"