Sankar
Sankar

Reputation: 7107

How to implicitly add the N in the prefix for NVARCHAR

I have an ASP.net page. There I can enter the Non-English language character into an input control (like a textbox). I want to store it in my SQL Server 2000 database as same language characters.

I pass the value as string to the nvarchar variable in my stored procedure.

My problem is, if you want to store the value in nvarchar character, you have to add N as prefix. How do I add this N in the prefix of sp_variable?

Thanks.

Upvotes: 0

Views: 1188

Answers (1)

Nikhil Vartak
Nikhil Vartak

Reputation: 5117

You need to add N prefix only to indicate that a hard-coded string value is nvarchar in SQL queries. C# string maps to both varchar and nvarchar of SQL Server.

To let SQL know you are passing unicode string, you should be doing this:

var cmd  = new SqlCommand("your_sp_name", sqlConn);
var sp_param = new SqlParameter("@sp_variable", SqlDbType.NVarChar);
sp_param.Value = "unicode_chars_string_value";
cmd.Parameters.Add(sp_param);

Upvotes: 6

Related Questions