简体   繁体   English

如何在NVARCHAR的前缀中隐式添加N

[英]How to implicitly add the N in the prefix for NVARCHAR

I have an ASP.net page. 我有一个ASP.net页面。 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. 我想以相同的语言字符将其存储在SQL Server 2000数据库中。

I pass the value as string to the nvarchar variable in my stored procedure. 我将值作为字符串传递给存储过程中的nvarchar变量。

My problem is, if you want to store the value in nvarchar character, you have to add N as prefix. 我的问题是,如果要将值存储在nvarchar字符中,则必须添加N作为前缀。 How do I add this N in the prefix of sp_variable ? 如何在sp_variable的前缀中添加此N

Thanks. 谢谢。

You need to add N prefix only to indicate that a hard-coded string value is nvarchar in SQL queries. 您只需要添加N前缀即可表示SQL查询中的硬编码字符串值为nvarchar C# string maps to both varchar and nvarchar of SQL Server. C# string映射到SQL Server的varcharnvarchar

To let SQL know you are passing unicode string, you should be doing this: 为了让SQL知道您正在传递unicode字符串,您应该这样做:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM