SQL Server 2005 - character encoding issue

2019-07-18 04:43发布

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.

2条回答
虎瘦雄心在
2楼-- · 2019-07-18 05:14
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

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-18 05:16

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....

查看更多
登录 后发表回答