SQL Server 和ASP .NET 编码问题
我的页面添加了 utf-8 元元素 + sql server 编码也是 utf。但是,当我创建记录并尝试发出包含 'ń' 等波兰语字符的条件的 SELECT 语句时,我看不到任何结果。我有什么想法吗?
另外,Sql Management Studio 显示带有波兰语字符的结果,但我不相信它......我猜想将记录放入数据库时出了问题......
或者我该如何排除故障?
谢谢,帕韦乌
my page has utf-8 meta element added + sql server encoding is also utf. However when I create record and try to issue SELECT statement with condition that contains POLISH characters like 'ń' , I see no results. Any ideas what am I missing?
ALSO Sql management studio shows result with POLISH characters , but I don't trust it.... I guess something is wrong with putting record into database...
Or how can I troubleshoot it?
Thanks,Paweł
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,我通过在
WHERE
子句中的文本前面加上“N”来解决它。例如,我有一个表“Person”,其中包含超过 21,000 个人名。最近将姓氏为“Krzemiński”的人添加到数据库中,并且在显示该行时该姓名显示正常(即“ń”字符显示正确)。但是,以下语句都没有返回任何记录:
...但是这些语句都返回了正确的记录:
当我执行以下语句时:
我得到了包含字母“n”(无变音符号)的所有 8900 条记录,但我确实 这样做了未获取包含“ń”字符的记录。我尝试使用所有波兰语字符 (ąćęłńóśźż) 进行最后一个查询,除了“ó”之外,所有这些字符都表现出相同的行为(即,返回具有较低 ASCII 等效字符的所有记录)。奇怪的是,“ó”按其应有的方式工作,仅返回 FamilyName 字段中带有“ó”的记录。
无论如何,解决方案是在搜索条件前加上“N”前缀,以明确将其声明为 Unicode。
因此,以下语句:
...都返回正确的记录集。
我感到困惑的原因是我有很多带有奇怪变音符号的记录,即使没有“N”前缀,它们也会返回正确的记录。到目前为止,我发现唯一需要显式“N”前缀的字符是波兰语字符。
I had the same issue, and I solved it by prefixing the text in the
WHERE
clause with "N".For example, I have a table 'Person' containing a bit over 21,000 names of people. A person with the last name "Krzemiński" was recently added to the database, and the name appears normal when the row is displayed (i.e., the "ń" character is displayed correctly). However, neither of the following statements returned any records:
...but these statements both returned the correct record:
When I executed the following statement:
I get all 8900 records that contain the letter "n" (no diacritic), but I do not get the record that contains the "ń" character. I tried this last query with all of the Polish characters (ąćęłńóśźż), and all of them except "ó" exhibit the same behavior (i.e., return all records with the lower-ASCII equivalent character). Weirdly, "ó" works as it should, returning only those records with an "ó" in the FamilyName field.
In any case, the solution was to prefix the search criterion with "N", to explicitly declare it as Unicode.
Thus, the following statements:
...both return the correct set of records.
The reason I was confused is that I have MANY records with weird diacritics, and they all return the correct records even without the "N" prefix. So far, the only characters I've found that require the explicit "N" prefix are the Polish characters.
根据此(已存档)Microsoft 支持问题:
处理时,必须在所有 Unicode 字符串前面加上前缀 N SQL Server 中的 Unicode 字符串常量
According to this (Archived) Microsoft Support Issue:
You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server
只需使用 nvarchar 而不是 varchar 作为保存记录的列的数据类型。
simply use nvarchar instead of varchar as the datatype of the column saving the record.