问题描述
如何将阿拉伯字符插入到 SQL Server 数据库中?我尝试将阿拉伯语数据插入表中,插入脚本中的阿拉伯语字符作为 '??????'
插入表中.
How can I insert Arabic characters into a SQL Server database? I tried to insert Arabic data into a table and the Arabic characters in the insert script were inserted as '??????'
in the table.
我尝试通过SQL Server Management Studio直接将数据粘贴到表中,成功准确地插入了阿拉伯字符.
I tried to directly paste the data into the table through SQL Server Management Studio and the Arabic characters was successfully and accurately inserted.
我四处寻找解决此问题的方法,一些线程建议将数据类型更改为 nvarchar
而不是 varchar
.我也试过这个,但没有任何运气.
I looked around for resolutions for this problems and some threads suggested changing the datatype to nvarchar
instead of varchar
. I tried this as well but without any luck.
如何在 SQL Server 数据库中插入阿拉伯字符?
How can we insert Arabic characters into SQL Server database?
推荐答案
对于能够存储 unicode 字符的字段,您必须使用类型 nvarchar
(或其他类似的类似 ntext
, nchar
).
For the field to be able to store unicode characters, you have to use the type nvarchar
(or other similar like ntext
, nchar
).
要在数据库中插入 unicode 字符,您必须使用 nvarchar
/SqlDbType.NVarChar
等参数类型将文本作为 unicode 发送.
To insert the unicode characters in the database you have to send the text as unicode by using a parameter type like nvarchar
/ SqlDbType.NVarChar
.
(为了完整起见:如果您正在动态创建 SQL(反对常见建议),您可以在字符串文字前放置一个 N 以使其成为 unicode.例如:insert into table (name) values (N'Pavan')
.)
(For completeness: if you are creating SQL dynamically (against common advice), you put an N before a string literal to make it unicode. For example: insert into table (name) values (N'Pavan')
.)
这篇关于如何将阿拉伯字符插入到 SQL 数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!