- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 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/
我是一名优秀的程序员,十分优秀!