SQL Server 和ASP .NET 编码问题

发布于 2024-09-19 09:38:01 字数 225 浏览 3 评论 0原文

我的页面添加了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

﹉夏雨初晴づ 2024-09-26 09:38:01

我遇到了同样的问题,我通过在 WHERE 子句中的文本前面加上“N”来解决它。

例如,我有一个表“Person”,其中包含超过 21,000 个人名。最近将姓氏为“Krzemiński”的人添加到数据库中,并且在显示该行时该姓名显示正常(即“ń”字符显示正确)。但是,以下语句都没有返回任何记录:

SELECT * FROM Person WHERE FamilyName='Krzemiński
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemiń%'

...但是这些语句都返回了正确的记录:

SELECT * FROM Person WHERE FamilyName LIKE 'Krzemi%'<br>
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemi%ski'

当我执行以下语句时:

SELECT * FROM Person WHERE FamilyName LIKE '%ń%'

我得到了包含字母“n”(无变音符号)的所有 8900 条记录,但我确实 这样做了获取包含“ń”字符的记录。我尝试使用所有波兰语字符 (ąćęłńóśźż) 进行最后一个查询,除了“ó”之外,所有这些字符都表现出相同的行为(即,返回具有较低 ASCII 等效字符的所有记录)。奇怪的是,“ó”按其应有的方式工作,仅返回 FamilyName 字段中带有“ó”的记录。

无论如何,解决方案是在搜索条件前加上“N”前缀,以明确将其声明为 Unicode。

因此,以下语句:

SELECT * FROM Person WHERE FamilyName LIKE N'%ń%'
SELECT * FROM Person WHERE FamilyName=N'Krzemiński'

...都返回正确的记录集。

我感到困惑的原因是我有很多带有奇怪变音符号的记录,即使没有“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:

SELECT * FROM Person WHERE FamilyName='Krzemiński
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemiń%'

...but these statements both returned the correct record:

SELECT * FROM Person WHERE FamilyName LIKE 'Krzemi%'<br>
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemi%ski'

When I executed the following statement:

SELECT * FROM Person WHERE FamilyName LIKE '%ń%'

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:

SELECT * FROM Person WHERE FamilyName LIKE N'%ń%'
SELECT * FROM Person WHERE FamilyName=N'Krzemiński'

...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.

通知家属抬走 2024-09-26 09:38:01

只需使用 nvarchar 而不是 varchar 作为保存记录的列的数据类型。

simply use nvarchar instead of varchar as the datatype of the column saving the record.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文