不显示 C# 的扩展字符

Extended characters not displaying C#

我目前正在使用 C# 开发 Web 应用程序。

其中一个在线表格允许用户更新他们的地址。

但是,当我在任何地址信息中输入例如:ÀîâãäåæéêìñóôõăąăĂąĄ

然后再次搜索同一用户他们的地址显示在屏幕上 like this。

如您所见,最后几个字符似乎有误。

数据库也出错了。

在发送字符串进行更新之前,我是否需要对字符串执行某些操作,目前我只是将文本字段中的任何内容转换为大写并将信息发送到我的存储过程。

,@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

请帮忙。注意我尝试更改为 nchar - 但我认为这可能是 C# 的问题? 谢谢

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);

您正在处理无法存储在 char 字段类型中的扩展字符集,您只能为此使用 ncharnvarchar,但请注意 space 对 Unicode 字符的要求将是 space.

的两倍

这是一个很好的 answer explaining the difference and here 是关于您应该使用的数据类型的文档。