1

I want to insert and update Arabic language into SQL Server by using stored procedure and parameters. I checked the other posts all they said you use nvarchar(100) or use N'الاسم العربي'.

My case is different: I am using stored procedure and parameters, how to put N before the parameter @patient_Name_Arabic this is my stored procedure:

ALTER PROCEDURE [dbo].[UPDATE_PATIENTS]
    @Patient_name VARCHAR(50),
    @Age INT,
    @Mobile VARCHAR(50),
    @Email VARCHAR(50),
    @Address VARCHAR(50),
    @Gender INT,
    @Patient_id VARCHAR(50),
    @Natid INT,
    @Patient_no INT,
    @insurance_card IMAGE,
    @ID_card IMAGE,
    @patient_Name_Arabic NVARCHAR(50)
AS 
    UPDATE [Patients]
    SET [Patient_Name] = @Patient_name, 
        [Age] = @Age,
        [Mobile] = @Mobile,
        [Email] = @Email,
        [Address] = @Email,
        [Gender] = @Gender,
        [Patient_id] = @Patient_id,
        [Natid] = @Natid,
        [insurance_card] = @insurance_card,
        [ID_card] = @ID_card,
        patient_Name_Arabic = @patient_Name_Arabic
    WHERE Patient_no = @Patient_no

I tried to put N before parameter @patient_Name_Arabic but it's not working.

N'@patient_Name_Arabic' or N"@patient_Name_Arabic" or N(@patient_Name_Arabic)

What is the correct way in my case to store Arabic language ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Abdullah
  • 983
  • 12
  • 26
  • 1
    For unicode chars, please use NVARCHAR as datatype – Harsh Shankar Feb 03 '19 at 18:52
  • 1
    The `N` is needed only for string literals to denote a Unicode string. The stored procedure parameter is already nvarchar (Unicode) so Unicode characters will be stored as long as the table column is nvarchar and you pass a Unicode value. – Dan Guzman Feb 03 '19 at 18:53
  • 1
    Read: [What is the difference between varchar and nvarchar](https://stackoverflow.com/questions/144283/what-is-the-difference-between-varchar-and-nvarchar) You have declared your parameters of type _varchar_, the sql engine tries to satisfy your request – Steve Feb 03 '19 at 18:53
  • Just use `NVarchar(50)` instead of `Varchar(50)` when declaring parameters – Hadi Feb 03 '19 at 18:56
  • **Side note:** `image` data type will be removed in a future version of SQL Server. Avoid using this data type in new development work, and plan to modify applications that currently use it. Use `varbinary(max)` instead. [See details here](http://msdn.microsoft.com/en-us/library/ms187993.aspx) – marc_s Feb 03 '19 at 20:37
  • Possible duplicate of [What is the difference between varchar and nvarchar?](https://stackoverflow.com/questions/144283/what-is-the-difference-between-varchar-and-nvarchar) – Joshua Feb 03 '19 at 20:40
  • A number of comments state that the OP has used `varchar` parameters. That is not true - `patient_Name_Arabic` is defined as `nvarchar` in the above code. – mjwills Feb 03 '19 at 20:41

1 Answers1

1

I found the solution I am using in my c# application the following code :

param[10] = new SqlParameter("@patient_Name_Arabic", SqlDbType.VarChar, 50);
            param[10].Value = patient_Name_Arabic;

I changed SqlDbType.VarChar, 50 to SqlDbType.NVarChar, 50

param[10] = new SqlParameter("@patient_Name_Arabic", SqlDbType.NVarChar, 50);
            param[10].Value = patient_Name_Arabic;

and its working correct and save arabic language i tried before in stored procedure in SQL server , i changed the application code also then its worked. Thank you for help

Abdullah
  • 983
  • 12
  • 26