問題描述
如何將阿拉伯字符插入到 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 數據庫中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!