[英]How can I send Hebrew text to SQL Server from a C# ASP.NET parameter?
When words_array[i]
is Hebrew text, the database shows '?????'
当
words_array[i]
是希伯来语文本时,数据库显示'?????'
in place of the word.代替这个词。
myCommand.CommandText = "INSERT INTO MyTable(word) VALUES (@word);
myCommand.Parameters.Add(new SqlParameter("@word", SqlDbType.Varchar, 50));
command.Parameters["@word"].Value = words_array[i];
I tried below, but got an error :我在下面尝试过,但出现错误:
Incorrect syntax near 'N'
'N' 附近的语法不正确
My attempt:我的尝试:
myCommand.CommandText = "INSERT INTO MyTable(word) VALUES (N'@word'N);
I tried this, too - problem: placed the text '@word' in place of the Hebrew word.我也试过这个 - 问题:将文本“@word”放在希伯来语单词的位置。
myCommand.CommandText = "INSERT INTO MyTable(word) VALUES (N'@word');
Change SqlDbType.VarChar
with SqlDbType.NVarChar
.将
SqlDbType.VarChar
更改为SqlDbType.NVarChar
。 There's no need to prefix strings when using parameterized queries.使用参数化查询时无需为字符串添加前缀。
The line :线路:
myCommand.Parameters.Add(new SqlParameter("@word",SqlDbType.VarChar,50));
Says that the parameter's type is a string using a single-byte codepage instead of a Unicode string.表示参数的类型是使用单字节代码页而不是 Unicode 字符串的字符串。 Strings in .NET are Unicode but this line tells the driver to convert the value to a single-byte encoding using the codepage specified by the thread's
CurrentCultureInfo
. .NET 中的字符串是 Unicode,但这一行告诉驱动程序使用线程的
CurrentCultureInfo
指定的代码页将值转换为单字节编码。
It should be它应该是
myCommand.Parameters.Add(new SqlParameter("@word",SqlDbType.NVarChar,50));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.