I'm using SQL Server 2008 as my database engine in a VS2010, C# ASP.NET web app. My project is Farsi (Persian) so I've used nvarchar
and ntext
as my data types.
I use following query to find rows from my database but nothing is returned, while I have a row with the specified keyword. Of course my keyword is in Persian (unicode).
What is going wrong here? Is it because of using Farsi language? How can I search in nvarchar
and ntext
columns containing unicode characters?
myCommand = new SqlCommand("select * from tblArticle where name LIKE '%" + txtSearch.Text + "%'", SQLConnection);
You should use the N'
prefix to indicate that you're searching for a Unicode string:
SELECT * FROM dbo.tblArticle WHERE name LIKE N'%......%'
Otherwise, you're converting your search string back to non-Unicode and then searching....
You must use COLLATE Latin1_General_BIN2
to get results. Works for Amharic for Ethiopians.
Select * From YourTableName where ColNameYouSearch LIKE N'%YourSerchCriteria%' COLLATE Latin1_General_BIN2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With