Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all, Good day. I have spent months over the net looking for answers on how should I save/retrieve a special character unicode(e.g. "\u20fa") in a string and save it to database(which in my case, it is postgreSQL). I just want my chemical formula string to be saved and viewed from database, like a subscript of 2, of chemical formula of 'water'. I've made some codes, but the special character appears as a question mark in the database (like this: ?).

Does anyone know how this is done? Ive tried to save a special character directly to the query, and its successfully saved as is to the database, then I tried to view it from my application, then it shows goofy characters. Maybe there's some encoding stuff i need to understand... Please help, i really need someone who knows this. :((

P.S. Im using SharpDevelop as IDE. With some dll's for database connection stuff.
Posted
Updated 22-Nov-10 0:10am
v2
Comments
Richard MacCutchan 23-Nov-10 5:17am    
Unicode is not UTF8, it is UTF16. As you can see above the character you are trying to save is a 16-bit character so it won't fit into UTF-8.

I know nothing about PostGres but a common problem with questions like this is that the destination object (database field, text string etc.) has been set up to hold ASCII characters only. Check the type definition of your field to see if it can hold Unicode characters.
 
Share this answer
 
Comments
Phillip Tampus 22-Nov-10 20:32pm    
I see. I have set the encoding in my PostGres database to unicode(Utf-8 as it says), but it still the same. So I started thinking there might be something to be done in the codes before saving to database. Anyway, thank you for replying Richard.
Okay, i finally got the answer. I guess this would help for future questions like this.

I think that this prob is more like on PostgreSQL, but I use SharpDevelop so i think its fine...

I didn't manage to store and get the characters by directly storing it through the query. This query which happens to be a string. What I did was to convert the line of string which contains the unicode character to byte array. Store it to the database, and upon retrieving it, I convert it again to unicode string. And that's it.
 
Share this answer
 

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