Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all, I want to save Korean Language in my MS Sql server table. but when i execute my procedure it save value like '???????' this. here is my sample code:-

alter PROCEDURE [dbo].[testsp]
	(	
		@Name	nvarchar(4000)
    )
AS

BEGIN

	SET NOCOUNT ON;

   INSERT INTO  dbo.tbl_test(testcolumn)

  VALUES (  @Name)

end



exicution code:-
exec [dbo].[testsp] @Name='안녕하세요'


and it save '????' question marks in my table column. can any one suggest me the solution.

What I have tried:

i search on google and got only one solution that use 'N' in your insert query. This solution working fine if i am using this like:-

alter PROCEDURE [dbo].[testsp]
	(	
		@Name	nvarchar(4000)
    )
AS

BEGIN

	SET NOCOUNT ON;

	set @Name=N'안녕하세요'

   INSERT INTO  dbo.tbl_test(testcolumn)

  VALUES (  @Name)

end


But i want to insert this value from my parameter which i passed in procedure.
Posted
Updated 8-Mar-21 20:45pm

1 solution

The "N" string prefix indicates that the string contains Unicode data:
'ABCDE'    Is ASCII data
N'ABCDE'   Is Unicode data
Similarly, the "N" in NVARCHAR indicates it is Unicode, without it the VARCHAR column is ASCII.
Your SP knows about and expects Unicode data, so it saves Unicode - but when you execute the procedure you have to hand it a Unicode string not an ASCII string.

So if your executing code passes a fixed Korean language string:
MS SQL 서버 테이블에 한국어를 저장하고 싶습니다.
Then it needs to be created with the Unicode prefix:
SQL
CALL MyStoredProcedure(N'MS SQL 서버 테이블에 한국어를 저장하고 싶습니다.')
Because if you don't, then it will pass an ASCII string and you will see "????" in your DB as a result:
SQL
CALL MyStoredProcedure('MS SQL 서버 테이블에 한국어를 저장하고 싶습니다.')


When you pass data to SQL from a presentation language such as C#, it will default to Unicode but other languages may use ASCII by default (for example, C)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900