如何将阿拉伯字符插入 SQL 数据库? [英] How to insert Arabic characters into SQL database?

查看:25
本文介绍了如何将阿拉伯字符插入 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 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆