Hi
I am doing a project in ASP.NET that at one point searches a SQL database for a postcode using Datasets:
string postcode = "%" + searchTerm.Trim().Replace(' ', '%') + "%";
SearchDataSet.SearchCustomerTableDataTable custTable = custAdapter.GetDataCustPostcode(postcode);
The GetDataCustPostcode
runs:
SELECT * FROM CustomerTable WHERE (CustomerPostcode LIKE @CustPostcode)
The expected results are returned when I try:
searchTerm = "BT14"
searches for a postcode
of %BT14%
or searchTerm = "BT14 7"
searches for a postcode
of %BT14%7%
custTable
is empty when I try:
searchTerm = "BT14 7D"
searches for a postcode
of %BT14%7D%
If I try writing a SQL query directly, i.e. typing:
SELECT * FROM CustomerTable WHERE (CustomerPostcode LIKE '%BT14%7D%')
Then the expected results are returned.
Can anyone advise why this is? Is it something to do with the characters in the string?
Thanks
Clivest