SQL Server : character showing question mark

2020-05-01 23:29发布

问题:

I'm using connection string in my ASP.net but its showing question mark as my entry in Arabic language, how I can convert the entry to work properly.

<add name="myodbc" 
     connectionString="Provider=SQLOLEDB;Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx;" />

回答1:

only you need to add 'N' IN STATMENT

insert into [xx].[dbo].[xx] (Name,Email,Telephone,Type_of_donation,donation_country,donation_category,transa‌​ction_time,payment_method,amount,referance_number) values ('','','',N'غير مشروط','xx','','xx','xx','32','16')

and i using this method also store arabic in SQL database



回答2:

As a SQL developer, you should use Unicode data types in applications. The Unicode data types are nchar, nvarchar, and ntext.

These data types use Unicode character representation. Code pages do not apply to these data types. Using Unicode data types gives you the ability to deal with Arabic data even the system collation is not Arabic.

When using Unicode data types, the best way to save your Arabic data from corruption when inserting, and updating is to add capital N before your Arabic string otherwise if the default database collation is not Arabic your data will be corrupted. When using N prefix with Unicode data types you save your Arabic data regardless the default database collation is Arabic or not. This is the golden key to deal with Unicode data types in the applications like VB, or ASP, even inside SQL server like stored procedures.

UPDATE TableName SET ColumnName = N'Arabic Text' WHERE id = 1000
INSERT INTO TableName (ColumnName) values(N’Arabic Text’)