将表情符号插入SQL Server

时间:2019-06-04 09:50:48

标签: sql sql-server

我正在尝试将表情符号插入我的MS SQL。

我使用以下查询插入:

Dim command As New SqlCommand("INSERT INTO [dbo].[emoji]([Message]) VALUES('" & "??????????☺️????????" & "')", SQLCon)

但是在我的数据库中,它显示为???????

来自评论
Microsoft SQL Server 2017(RTM)-14.0.1000.169(X64)2017年8月22日17:04:49版权所有(C)Windows 10 Home 10.0(Build 17134:)上的Microsoft Corporation Express Edition(64位)

我如何保存表情符号,因为它似乎在数据库中。

4 个答案:

答案 0 :(得分:3)

尝试一下。

Dim command As New SqlCommand("INSERT INTO [dbo].[emoji]([Message]) VALUES(N'" & "??????????☺️????????" & "')", SQLCon)

答案 1 :(得分:3)

我强烈建议您对查询进行参数设置,不要注入值。然后,只要您将参数声明为正确的数据类型,就可以正常工作。像这样:

Dim Emojis As String = "??????????☺️????????"

Dim SQL As String = "Insert into [dbo].[emoji]([Message]) VALUES(@Message);"
Dim command As New SqlCommand(SQL,SQLCon)

command.Parameters.Add("@Message", SqlDbType.NVarChar,100).Value = Emojis 'Guessed Length for the parameter

答案 2 :(得分:0)

您可以尝试以下方法:

declare @t table (emoji nvarchar(50))

Insert into @t VALUES(N'??????????☺️????????')


select * from @t

答案 3 :(得分:0)

您应为该列使用NVARCHAR数据类型。 例如。

declare @tbl table(message nvarchar(50))
insert into @tbl values(N'????????')
select * from @tbl

我建议您必须使用SqlParameter来插入或更新SQL列中的数据。