在SQL Server 2012 Express中的Unicode [英] Unicode in SQL Server 2012 Express

查看:236
本文介绍了在SQL Server 2012 Express中的Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#程序将一些unicode字符(如中文字符)插入SQL Server 2012数据库。

I am inserting some unicode characters such as Chinese characters using a c# program into a SQL Server 2012 database.

我要插入的列是 nvarchar ,但仍然获得而不是正确的字符。我从twitter收到tweet和插入到数据库。

The column I am trying to insert is nvarchar, but am still getting ??????? instead of the correct characters. I am getting tweets from twitter and inserting it into a database.

我使用的是SQL Server 2012 Express。我必须安装任何语言包或更改设置吗?我不太熟悉SQL Server。

I am using SQL Server 2012 Express. Must I install any language packages or change the settings? I am not really familiar with SQL Server.

这是我如何使用c#将代码插入数据库:

This is how i use c# to insert the codes into database:

String command4 = "INSERT INTO  tweets ([username], [createdDate], [tweet]) Values ('" + item.user.screen_name + "' , '" + item.created_at + "' ,N'" + escapedString + "')";

SqlCommand insertTweet = new SqlCommand(command4, connectionstring);

insertTweet.ExecuteNonQuery();

谢谢!

推荐答案

将字符作为SQL字符串传递时,始终以N开头:

When passing the characters as SQL strings, always precede with an "N":

N'Unicode'

而不只是

'Unicode'

或在您的情况下:

@"INSERT INTO tweets ([username], [createdDate], [tweet]) 
Values (N'" + item.user.screen_name + "' , '" + item.created_at + "' , N'" + escapedString + "')"


$ b b

顺便说一下,您应该使用参数 。它会立即解决许多问题(如你有一个,日期和数字格式,安全...)

By the way, you should use parameters. It would solve many problems at once (like the one you have, date and number formats, security...)

这篇关于在SQL Server 2012 Express中的Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆