开发者

SQL query doesn't find cities that begin with č, ć, š, ž, etc

My SQL query doesn't find cities that begin with for instance č, but does find cities which have č in their name but begin with regular English letters.

The City column in the database is of nvarchar type.

What is the solution for this problem?

I am using an SQLite database.

    cmdSQLite = new SQLiteCommand("SELECT RegistrationNumber, DocumentName, 
    Performer, BuiltYear, ReferatCardNumber , City, Municipalities , StreetName 
    FROM Geotest WHERE LOWER (City) = @City", connectionSQLite);

    SQLiteParameter parameterCity = new SQLiteParameter();
    parameterCity.Value = comboBoxCitySearch.Text.ToLower();
    parameterCity.ParameterName = "@City";
    cmdSQLite.Parameters.Add(parameterCity开发者_JS百科);


I think your problem might be related to unicode string in SQL Server. This might help

http://support.microsoft.com/kb/239530

When dealing with Unicode string constants in SQL Server you must precede all Unicode strings with a capital letter N, as documented in the SQL Server Books Online topic "Using Unicode Data". The "N" prefix stands for National Language in the SQL-92 standard, and must be uppercase. If you do not prefix a Unicode string constant with N, SQL Server will convert it to the non-Unicode code page of the current database before it uses the string.

UPDATE: My mistake, I did not read the question correctly, I thought we were talking about SQL Server. Reading the SQL Lite documentation, http://www.sqlite.org/faq.html#q18

The default configuration of SQLite only supports case-insensitive comparisons of ASCII characters. The reason for this is that doing full Unicode case-insensitive comparisons and case conversions requires tables and logic that would nearly double the size of the SQLite library. The SQLite developers reason that any application that needs full Unicode case support probably already has the necessary tables and functions and so SQLite should not take up space to duplicate this ability.


Here is solution:

parameterCity.Value = comboBoxCitySearch.Text;

Dont use C# function comboBoxCitySearch.Text.ToLower(); Just in SQL use:

WHERE LOWER(City) = LOWER(@City)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜