我在做一個項目,ASP.NET,在一個點地搜索郵政編碼SQL數據庫使用的數據集:搜索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%')
然後返回預期結果。
任何人都可以提出這是爲什麼?這與字符串中的字符有關嗎?
感謝
Clivest
這很奇怪!當我今天早上嘗試它時,它工作。我根本沒有修改代碼。也許重新啓動幫助?無論如何,它現在都正常工作。謝謝 – Clivest 2010-08-13 09:37:16