Click here to Skip to main content
15,883,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to store a value in the database with the following code that uses a stored procedure.
C#
cmd.Parameters.Add("@c128", SqlDbType.NChar, 13);
cmd.Parameters["@c128"].Value = c128;


c128 is a string containing 13 characters.

The values are:

[0] 170 'ª' char
[1] 103 'g' char
[2] 87 'W'  char
[3] 86 'V'  char
[4] 106 'j' char
[5] 73 'I'  char
[6] 33 '!'  char
[7] 116 't' char
[8] 36 '$'  char
[9] 131 'ƒ' char
[10]    47 '/'  char
[11]    109 'm' char
[12]    171 '«' char


But immediately after I Execute the stored procedure, the value in the database is:
[0] 170 'ª' char
[1] 103 'g' char
[2] 87 'W'  char
[3] 86 'V'  char
[4] 106 'j' char
[5] 73 'I'  char
[6] 33 '!'  char
[7] 116 't' char
[8] 36 '$'  char
[9] 63 '?'  char
[10]    47 '/'  char
[11]    109 'm' char
[12]    171 '«' char


It replaced character 131 with a question mark.

I am clueless as to why this is happening.

Thanks,
Bryan
Posted
Updated 27-Oct-11 10:52am
v2
Comments
Philippe Mori 27-Oct-11 18:07pm    
They are not using the same char set. Why not store string and works in Unicode?

What is the collation of the database field?

see: SQL Server Collation Fundamentals[^]
 
Share this answer
 
Change the database column data type to nchar/nvarchar (preferred) and it should resolve the issue
 
Share this answer
 
v2

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