Reputation: 3345
I am importing terms from a DB that contain foreign characters of all kinds. When I have japanese characters or chinese, I cannot run an update statement on the table since it cannot match the terms;
sqlUpdate = "Update QueryData set LastSearchDate ='" & DateTime.Now.ToString & "'" & "
where QueryTerms = '" & item & "'"
item is the search terms and it works fine for all other characters except when it is japanese. Now if I did it in sql server 2005 I would have to put an N in front of the term to find a match.
select * from QueryData where queryTerms =N'だしの素'
Is there a way to check a strings encoding in .net so that I can then encode it before running the query or is there an equivalent to the N in .net there has to be a more easier way of handling this.
Upvotes: 0
Views: 199
Reputation: 1499800
It's quite possible that using parameterized queries here will simply sort out your problem - as well as not being vulnerable to SQL injection attacks. Keep your data (the query value) away from your code (the SQL) - that way you don't have to represent everything as a string, which avoids all kinds of issues.
See the docs for SqlCommand.Parameters
for an example of how to use parameterized queries.
Upvotes: 2