gpt4 book ai didi

c# - SELECT .... WHERE something equals with 汉字

转载 作者:行者123 更新时间:2023-11-30 13:48:02 28 4
gpt4 key购买 nike

在 C# 窗口应用程序中,当我这样做时

select * from myTable where category = '牛奶'

select * from myTable where category = 'baby牛奶'

结果不返回任何行。

但是

select * from myTable where category = 'baby'

此结果返回一些行。谁能告诉我为什么?

注意:在myTable中,某些类别的列有一些值带有牛奶baby牛奶,我在窗口应用程序上显示汉字没有问题。

牛奶是汉字。

最佳答案

这不是 C# 问题,而是 SQL 问题。

确保传入的 SQL 字符串在 SQL 中被解释为 Unicode 字符串,方法是在它前面加上 N(SQL Server,MySQL):

select * from myTable where category = N'牛奶'

参见 Constants (Transact-SQL)在 MSDN 上。

Unicode strings

Unicode strings have a format similar to character strings but are preceded by an N identifier (N stands for National Language in the SQL-92 standard). The N prefix must be uppercase. For example, 'Michél' is a character constant while N'Michél' is a Unicode constant. Unicode constants are interpreted as Unicode data, and are not evaluated by using a code page. Unicode constants do have a collation. This collation primarily controls comparisons and case sensitivity. Unicode constants are assigned the default collation of the current database, unless the COLLATE clause is used to specify a collation. Unicode data is stored by using 2 bytes per character instead of 1 byte per character for character data.

关于c# - SELECT .... WHERE something equals with 汉字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14006579/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com