开发者

store arabic in SQL database

I tried to store Arabic string in SQL 2008 da开发者_如何学Pythontabase but it converted to " question mark " why ? and what should I do ?


You need to choose an Arabic collation for your varchar/char columns or use Unicode (nchar/nvarchar)

CREATE TABLE #test
(
col1 VARCHAR(100) COLLATE Latin1_General_100_CI_AI,
col2 VARCHAR(100) COLLATE Arabic_CI_AI_KS_WS,
col3 NVARCHAR(100)
)
INSERT INTO #test VALUES(N'لا أتكلم العربية',N'لا أتكلم العربية',N'لا أتكلم العربية')

Note the N before values in insert statement above. If you do not mention it, system will treat the values as Varchar, not NVarchar.

SELECT * FROM #test

Returns

col1                           col2                           col3
------------------------------ ------------------------------ ------------------------------
?? ????? ???????               لا أتكلم العربية               لا أتكلم العربية

To see a list of Arabic collations use

SELECT name, description 
FROM fn_helpcollations() 
WHERE name LIKE 'Arabic%'


All of what you have to do is to make sure that

the column Data type is nvarchar()

store arabic in SQL database

after that I inserted Arabic with no problems

store arabic in SQL database


You can change the collation on the database level instead of changing for each column in the database:

USE master;
GO
ALTER DATABASE TestDB
COLLATE Arabic_CI_AI;
GO


insert into table (column) values (N'xxx').)

You should put N before string to make it unicode


Add 'N' before every value. example:

INSERT INTO table1 VALUES(N'aaaaaaaaa',N'ששששששששששששש',N'aaaaaaaaaaa',N'ششششششششششش')


Try using this:
the column Data type is nvarchar()

INSERT INTO CompanyMaster values(N'" + txtCompNameAR.Text + "',N'" + txtCompAddressAR.Text + "','" + txtPh.Text + "')


This is helpful but work here's what works for me in all cases

ALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

GO

ALTER DATABASE [database] COLLATE ARABIC_CI_AS;

GO

ALTER DATABASE [database] SET MULTI_USER;

GO

update: eventually I have to change datatype varchar to nvarchar in my project


make sure all your tables and varchar columns have the collation of utf8_general_ci


Iti is easy to store Arabic string in Oracle. Use this code:

declare @P_CUSTOMER_NAME  nchar(50) 
set @P_CUSTOMER_NAME2=N'أختبار'

The above will save in Oracle just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜