need simple help with Unicode

  • Thread starter Thread starter Kent Rollins
  • Start date Start date
K

Kent Rollins

I am trying to insert a Unicode string into SQL Server and then read
it back out. I wrote a simple little test app and somewhere my string
is getting converted to ANSI or something similar. Can anyone sport
what I'm doing wrong or give me some ideas to check out?

cmd.CommandText = "CREATE TABLE MyTable ( MyData nvarchar(50) )";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO MyTable (MyData) VALUES ('123 \u0080
321')";
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT MyData FROM MyTable";
object obj = cmd.ExecuteScalar();
string s = (string)obj;

This results in a s == "123 ? 321" where the question mark is actually
a question mark, not 0x80.

Kent Rollins
Atlanta, GA
 
Kent,

Try to prepend N to your string value:

.... VALUES(N'123...

HTH,
Alexander
 
Back
Top