Reputation: 4341
I'm trying to get customers based on customer code:
var customer = GetAllCustomers()
.FirstOrDefault(c => c.CustomerCode.ToLower().Trim() ==
customerCode.ToLower().Trim());
In one case, customerCode
is "Andreas Graßl" (I think it's a German name)
However, in the database (SQL Server 2008 R2) the data is saved as "Andreas Grassl" (ß became ss), and my query does not find a match.
Can someone please tell me whether this is a collation thing in the database or is this a culture thing in C#?
How can I fix it so that my query will return a match?
Upvotes: 0
Views: 2450
Reputation: 56697
One solution could be to perform a "sounds like" search using DIFFERENCE:
SELECT *
FROM Person
WHERE DIFFERENCE(Person.LastName, 'Graßl') >= x
Upvotes: 1
Reputation: 3188
string str1="Andreas Graßl";
string str2="Andreas Grassl";
Console.WriteLine(string.Equals(str1,str2)); //False
Console.WriteLine(string.Equals(str1,str2,StringComparison.CurrentCulture)); //True
So I suggest you change your code with string.Equals()
Details: http://msdn.microsoft.com/en-us/library/vstudio/cc165449.aspx
Upvotes: 3
Reputation: 3214
In German, ß
and ss
are used somewhat interchangeably. Is it possible the user input was ss
during saving and later ß
during lookup?
Upvotes: 0
Reputation: 1
Please you run the script to re-updating CustomerCode by following Unicode format:
UPDATE Customer SET CustomerCode = N'Andreas Graßl' WHERE CustomerID = [YourCustomerID]
Hope this will help you!!
Upvotes: 0