Question

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?

Était-ce utile?

La solution

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

Autres conseils

One solution could be to perform a "sounds like" search using DIFFERENCE:

SELECT *
FROM Person
WHERE DIFFERENCE(Person.LastName, 'Graßl') >= x

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!!

In German, ß and ss are used somewhat interchangeably. Is it possible the user input was ss during saving and later ß during lookup?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top