Querying Utf 8 with C# by Using Prepared Statement

Sorry if this question is duplicate and also very simple question. However I can't solve my query problem. I'm new to C# queries. I need to do query like " select * from table where att=N'ğasd' ". I have to use N, otherwise it does not match.

I want to use prepared statement, but when I do something like:

commandString = "select * from table where att=N@param;";
command.Parameters.AddWithValue("@param", "ğasd");

It gives " Invalid column name 'N@param' ".

My attribute is nvarchar(50). There is also another interesting thing. Another attribute like att2 is also nvarchar(50) and my database's collation is "SQL_Latin1_General_CP1_CI_AS", but att2='ğasd' works fine. I solved this problem with adding "N". This time like I said, I stuck on prepared statement problem.

Am I doing something wrong? please help.

Jon Skeet
people
quotationmark

The N part is a prefix for a literal. You shouldn't need to to that. I would expect this to work:

commandString = "select * from table where att=@param";
command.Parameters.Add("@param", SqlDbType.NVarChar).Value = "ğasd";

Note the different way I'm specifying the parameter, to explicitly make it an NVarChar parameter. I'd have hoped that the right parameter type would have been used anyway, but maybe not...

people

See more on this question at Stackoverflow