Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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:
SQL
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"
 
Share this answer
 
Comments
Christopher Smit 22-Feb-14 7:59am    
I cannot find NVARCHAR... I'm using MySQL Workbench 6.0
OriginalGriff 22-Feb-14 8:18am    
Yes, but what version of MySql is behind that?
Christopher Smit 24-Feb-14 14:37pm    
Sorry for late reply... Build 6.0.7.11215

Do you know if there is an alternative to NVARCHAR in some versions?
OriginalGriff 24-Feb-14 14:46pm    
Build 6.0.7.11215 is teh SQL Wrokbench version, not the MySql DB Engine version.

Try
VARCHAR(n) CHARSET utf8
Christopher Smit 24-Feb-14 14:53pm    
I am able to set the CHARSET to utf8, I cannot type VARCHAR(n) at all. Where do I get the DB Engine version and what is the difference?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900