-1

I have some french characters stored in a text column in Sql Server(not ntext but text). When I display this on html i get some funny question mark characters in the string.

Even if I convert the text to nvarchar(max) and display on html I still get the same error.

How do I convert the french characters in the text field to UTF-8 correctly? I am using C#, .NET 4.5.

Thank you, GMAT

user2227484
  • 83
  • 2
  • 12
  • https://msdn.microsoft.com/en-us/library/ms404377(v=vs.110).aspx should be of help to you – Satya Jul 28 '15 at 22:18
  • It may or may not be a database issue. – Sebas Jul 28 '15 at 22:19
  • Please see: http://stackoverflow.com/a/11432833/1291428. Mostly this answer is for mysql, but some parts apply to any system. – Sebas Jul 28 '15 at 22:20
  • 1
    It could be a mismatched HTML encoding. Try with `` – Lucas Trzesniewski Jul 28 '15 at 22:20
  • `text` will not store French characters properly. You need `ntext`. Now, if you started with `text` and then "converted" to `nvarchar`, you have already lost the unicode characters. You need to use a unicode field type `ntext` or `nvarchar` and import the data fresh. – Sam Axe Jul 28 '15 at 22:24
  • I think you are right Sam Axe – user2227484 Jul 29 '15 at 12:57
  • The content displays fine on a browser but I am trying to send the content to a web service using Content type = application/x-www-form-urlencoded – user2227484 Jul 31 '15 at 21:05

1 Answers1

0

Fixed it thus:

Encoding wind1252 = Encoding.GetEncoding(1252);
Encoding utf8 = Encoding.UTF8;
byte[] wind125Bytes = wind1252.GetBytes(input);
byte[] data = Encoding.Convert(wind1252, utf8, wind125Bytes);
user2227484
  • 83
  • 2
  • 12