3

I have a problem when I try to insert arabic text as sql variable in sql server 2008 , inserts data like this value ???? .How to solve this?

This is my query

insert into tests values(N''+@name)

The result shows like this:

screenshot

mustaccio
  • 18,234
  • 16
  • 48
  • 57
achu
  • 43
  • 1
  • 7

2 Answers2

4

Try this and you will see what Data Type you shoule use :

DECLARE @V1 VARCHAR(50) = 'فيلم';
DECLARE @V2 NVARCHAR(50) = N'فيلم'

SELECT @V1 Varchar_Col, @V2 NVarchar_Col

Demo

Update:

Try to use SqlDbType.NVarChar when you pass your Parameter.

and you can also try with :

INSERT INTO tests (ID_Number) VALUES (@name)
Ilyes
  • 14,640
  • 4
  • 29
  • 55
2

Use unicode datatypes for your data storage and begin your strings with N literal like this:

declare @t table(col Nvarchar(100)); 
insert @t (col) values (N'your text');

Or use the appropriate COLLATION with non-unicode data types but pass your values as unicode ones (with N) because your server/database collation seems to be different from arabic

sepupic
  • 8,409
  • 1
  • 9
  • 20
  • I only pass variable @name from my c# code to the stored procedure.How to use N' for the variable @name? – achu May 16 '17 at 13:35
  • define your c# parameter as unicode one; check your procedure parameter type as well – sepupic May 16 '17 at 13:40
  • Finally the Issue solved using collation on database.@sepupic suggested me above for this method.Thank you @sepupic. I used this link http://www.serverintellect.com/support/sqlserver/change-database-collation. Thank you all for helping me. – achu May 23 '17 at 11:11