question

sanket pathre avatar image
sanket pathre asked

Convert sql parameter to unicode value

hi friend

How to convert sql parameter value to Unicode. I know that When dealing with Unicode string constants in SQL Server we must precede all Unicode strings with a capital letter N. If you do not prefix a Unicode string constant with N, SQL Server will convert it to the non-Unicode code page of the current database before it uses the string.

I have store procedure which accept various parameters which i insert into table Now, My question is how will i assure that all data inserted must be in Unicode format. eg:

INSERT INTO Users(FirstName,LastName)VALUES(N'XYZ',N'PQR') values prefix with Unicode string

INSERT INTO Users(FirstName,LastName)VALUES(@firstName,@lastName) How to prefix parameters with unicode string?

I call this store procedure from C# code.

Any help appreciated Thanks in Advance

unicode
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kristen avatar image
Kristen answered

INSERT INTO Users(FirstName,LastName)VALUES(@firstName,@lastName) How to prefix parameters with unicode string?

SQL Server will automatically convet the parameters to UNICODE if the columns [FirstName] and [LastName] are defined as Unicode - i.e. Nvarchar or Nchar

Your stored procedure can also defined the Parameters as Nvarchar or Nchar to indicate that they should be treated as UNICODE (but if the columns [FirstName] and [LastName] are not defined as Unicode - i.e. they are Varchar - then the data will be converted back again before being inserted

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rainmaker 2 avatar image
rainmaker 2 answered

Dim pa1 As New SqlParameter("@firstName", Data.SqlDbType.NVarChar, 128)

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.