简体   繁体   English

如何将希伯来语文本从 C# ASP.NET 参数发送到 SQL Server?

[英]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.

相关问题 如何在ASP.NET C#中从SQL Server选择日期到TextBox - How can I select date from SQL Server to TextBox in asp.net c# 如何使用ASP.NET从C#中的SQL Server表中自动完成TextBox中的值 - How can I autocomplete values in a TextBox from SQL Server table in C# with ASP.NET 如何通过C#ASP.net从SQL Server中的文本框存储日期 - How to store date from text box in SQL Server through C# ASP.net 如何使用C#ASP.NET HttpClient将数据从Sql Server发送到另一个Sql Server(未链接) - How to send data from a Sql Server to another Sql Server (Not Linked) Using C# ASP.NET HttpClient 如何从ASP.NET MVC中的SQL Server数据库向多个收件人发送电子邮件? - How can I send email to multiple recipients from SQL Server database in ASP.NET MVC? 如何将对象从C#WebApp发送到ASP.NET WebAPI - how can I send object from c# webapp to asp.net webapi 如何从C#Asp.Net方法发送HTTP Post? - How can I send a HTTP Post from a C# Asp.Net method? 如何在asp.net C#中创建从URL获取参数的SQL查询# - How can I create SQL Query which Takes Parameters from URL in asp.net C# 如何在C#asp.net中使用SqlDataReader对SQL Server查询使用参数,该参数是查询本身的一部分 - How to use a parameter for a SQL Server query that is part of the query itself using SqlDataReader in C# asp.net SMTP服务器无法从托管c#asp.net发送电子邮件 - SMTP server can't send emails from hosting c# asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM