2

I am currently working on a web application using C#.

One of the online forms allows the user to update their address.

However, when I enter for example : ÀîâãäåæéêìñóôõăąăĂąĄ into any of the address info

and then search for the same user again their address is displayed on the screen like this.

As you can see the last characters seem to be wrong.

Wrong in the database too.

Do I need to do something to the string before I send it for update, at the moment I just convert whatever is in the text field to uppercase and send the information to my stored procedure.

,@p_AddressLine1 char(40)=NULL
,@p_AddressLine2 char(40)=NULL
,@p_AddressLine3 char(40)=NULL
,@p_AddressLine4 char(40)=NULL
,@p_AddressLine5 char(40)=NULL

Please help. Note Ive tried changing to nchar - but I think this may be a C# thing? Thanks

user.PostCode = this.tbPostCode1.Text.ToUpper().Trim() + " " + this.tbPostCode2.Text.ToUpper().Trim();
        user.AddressLine1 = this.txtAddressLine1.Text.ToUpper().Trim();
        user.AddressLine2 = this.txtAddressLine2.Text.ToUpper().Trim();
        user.AddressLine3 = this.txtAddressLine3.Text.ToUpper().Trim();
        user.AddressLine4 = this.txtAddressLine4.Text.ToUpper().Trim();
        user.AddressLine5 = this.txtAddressLine5.Text.ToUpper().Trim();



        user.Update(user);
ck29
  • 23
  • 4
  • What is your database default collation? e.g. `select serverproperty('collation')` – Eugene Komisarenko Apr 24 '17 at 18:57
  • SQL_Latin1_General_CP1_CI_AS – ck29 Apr 24 '17 at 18:59
  • When you use the debugger before presenting the info on a web page, is the value still wrong? Also, please read [this](http://stackoverflow.com/questions/1696619/displaying-unicode-symbols-in-html) – CodingYoshi Apr 24 '17 at 19:03
  • Yes the value is still wrong just before display. – ck29 Apr 24 '17 at 19:08
  • Is it corrupted before your stored procedure is called? – Eugene Komisarenko Apr 24 '17 at 19:09
  • No I can see in the debugger the format is just changed to upper text but not corrupt – ck29 Apr 24 '17 at 19:12
  • You mentioned you tried changing to `nchar`, did you change the parameter type and the field type in the table too? You would also need to re-run the update though, since `char` does not really support Unicode by design you cannot store characters like these in it. – Eugene Komisarenko Apr 24 '17 at 19:14
  • The field type goes to the DB as "String", just changed the parameter type...not the field type in the table – ck29 Apr 24 '17 at 19:18
  • And what is the field type in the table? If the string is correct before calling the sp you might be trying to squeeze Unicode characters to `char`. – Eugene Komisarenko Apr 24 '17 at 19:20

1 Answers1

0

You are dealing with extended character set which cannot be stored in char field type and you can only use nchar or nvarchar for that, but be aware about the space requirement for the Unicode characters which will take as twice as more space.

Here is a good answer explaining the difference and here is the documentation on the data types you should be using instead.

Community
  • 1
  • 1
Eugene Komisarenko
  • 1,533
  • 11
  • 25
  • Thank you so much this worked a treat!!!!! Still coming through in CSV wrong though - comes through as: ÀÎÂÃÄÅÆÉÊÌÑÓÔÕĂĄĂĂĄĄ – ck29 Apr 24 '17 at 20:03
  • This time it looks more like Unicode character encoded as HTML Entity – Eugene Komisarenko Apr 24 '17 at 20:27