【发布时间】:2011-03-28 22:19:04
【问题描述】:
我正在 ASP.NET 中做一个项目,该项目有一次使用数据集在 SQL 数据库中搜索邮政编码:
string postcode = "%" + searchTerm.Trim().Replace(' ', '%') + "%";
SearchDataSet.SearchCustomerTableDataTable custTable = custAdapter.GetDataCustPostcode(postcode);
GetDataCustPostcode 运行:
SELECT * FROM CustomerTable WHERE (CustomerPostcode LIKE @CustPostcode)
我尝试时返回预期的结果:
searchTerm = "BT14" 搜索 %BT14% 的 postcode
或 searchTerm = "BT14 7" 搜索 %BT14%7% 的 postcode
我尝试时custTable 为空:
searchTerm = "BT14 7D" 搜索 %BT14%7D% 的 postcode
如果我尝试直接编写 SQL 查询,即键入:
SELECT * FROM CustomerTable WHERE (CustomerPostcode LIKE '%BT14%7D%')
然后返回预期的结果。
谁能告诉这是为什么?和字符串中的字符有关系吗?
谢谢
克莱夫斯特
【问题讨论】:
-
这很奇怪!当我今天早上尝试它时,它起作用了。我根本没有修改代码。也许重启有帮助?无论如何,现在一切正常。谢谢
标签: sql asp.net dataset sql-like