HTML Symbols are being displayed as a question mar

2019-04-27 23:03发布

Today i noticed that html symbols such as: ★ are being displayed in my database as a question mark.

I'm using varchar as type and the database i am using is microsoft sql 2008.

Does anyone know a fix for this?

3条回答
疯言疯语
2楼-- · 2019-04-27 23:19

Define the symbol as an NVARCHAR instead of a VARCHAR

查看更多
疯言疯语
3楼-- · 2019-04-27 23:19
insert into tablename values (N'★ ') 

above is the syntax for inserting and make sure your field data type is nvarchar or try this test example

create table test (abc nvarchar)
insert into test values (N'★ ')
 select * from test
查看更多
Bombasti
4楼-- · 2019-04-27 23:26

You need to use NVARCHAR datatype for your column, VARCHAR datatype can only be use for non-unicode character.

if you are storing unicode characters in your datatype you should use NVARCHAR datatypes and when inserting Data into your Column use the N prefix telling sql server there will be some unicode characters in the passed string.

With VARCHAR DataType

CREATE TABLE #Temp (Column1 VARCHAR(100))
INSERT INTO #Temp VALUES('★')
SELECT * FROM #Temp

Result

╔═════════╗
║ Column1 ║
╠═════════╣
║ ?       ║
╚═════════╝

With NVARCHAR DataType

CREATE TABLE  #Tempn (Column1 NVARCHAR(100) )
INSERT INTO #Tempn VALUES(N'★')        --<-- N prefix for Unicode Characters
SELECT * FROM #Tempn

Result

╔═════════╗
║ Column1 ║
╠═════════╣
║ ★       ║
╚═════════╝
查看更多
登录 后发表回答