开发者

SQL Server 2005 - character encoding issue

开发者 https://www.devze.com 2023-02-05 22:39 出处:网络
I\'m trying to store this value : țșșțșțșțșîăâ./,șllkoăîâ= into a column in SQL Server.

I'm trying to store this value : țșșțșțșțșîăâ./,șllkoăîâ= into a column in SQL Server.

The column is nvarchar(1000) and the insert statement looks like

N'țșșțșțșțșîăâ./,șllkoăîâ=' 

But the data inside is still showing up like : ?????????îaâ./,?llkoaîâ=

Any ideas on what I could try ?

EDIT

I just realized that I had changed the datatype in the database , but the linq2sql mapping remained with varchar instead of nvarchar.

That's what was causing the issue - I only saw that after trying the manual insert.

Thanks. 开发者_Go百科


CREATE TABLE Test (test nvarchar(1000))
INSERT Test (test) VALUES (N'țșșțșțșțșîăâ./,șllkoăîâ=')

-- SSMS query pane = correct results
SELECT * FROM Test

Now, right click the table in Object Explorer, "Edit top 200 rows" or "SELECT TOP 1000 rows" gives correct results in SSMS 2008 for me

Next, without N prefix. Data is broken as per your question

INSERT Test (test) VALUES ('țșșțșțșțșîăâ./,șllkoăîâ=')
SELECT * FROM Test
--gives ?????????îaâ./,?llkoaîâ=

So, this shows that SSMS and SQL are behaving exactly as advertised: please show us the exact code (or method) you are using to insert the data


How are you adding this to your table?? In Mgmt Studio??? What statement do you use??

If you have NVARCHAR columns, you must use the N'...' syntax with the leading N prefix for this to work:

INSERT INTO dbo.YourTable(someColumn)
 VALUES(N'țșșțșțșțșîăâ')

If you omit the N prefix, Mgmt Studio will convert this to non-Unicode VARCHAR temporarily....

0

精彩评论

暂无评论...
验证码 换一张
取 消