How to insert Arabic characters into SQL database?(如何将阿拉伯字符插入 SQL 数据库?)
问题描述
如何将阿拉伯字符插入 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 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将阿拉伯字符插入 SQL 数据库?


- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01