简体   繁体   English

将日语字符写入表格

[英]Write japanese characters into table

When trying to save a string into my DB table, they get saved as question marks. 尝试将字符串保存到我的数据库表中时,它们将另存为问号。

I have already checked out this question (and many more): Why is sql server storing question mark characters instead of Japanese characters in NVarchar fields? 我已经检查了这个问题(还有更多): 为什么sql server在NVarchar字段中存储问号字符而不是日语字符?

Unfortunately, nothing wielded any result for me. 不幸的是,没有任何事情对我产生任何影响。 I have had the Collation set to "SQL_Latin1_General_CP1_CI_AS" at the start, but I changed it to "Japanese_CI_AS" later on. 一开始,我已将归类设置为“ SQL_Latin1_General_CP1_CI_AS”,但后来我将其更改为“ Japanese_CI_AS”。 Still no change. 仍然没有变化。

My code looks similar to this (sorry for not having the real code, it's on my laptop): 我的代码与此类似(抱歉,没有真正的代码,它在我的笔记本电脑上):

string query = "INSERT INTO ArticlesTBL (ArticleTitle, ArticleContent, 

ArticleType, ArticleImg, ArticleBrief,  ArticleDateTime, ArticleAuthor, ArticlePublished, ArticleHomeDisplay, ArticleViews)";
query += " VALUES (@ArticleTitle, @ArticleContent, @ArticleType, @ArticleImg, @ArticleBrief, @ArticleDateTime, @ArticleAuthor, @ArticlePublished, @ArticleHomeDisplay, @ArticleViews)";

SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.Parameters.AddWithValue("@ArticleTitle", ArticleTitleTextBox.Text);
myCommand.Parameters.AddWithValue("@ArticleContent", ArticleContentTextBox.Text);
// ... other parameters
myCommand.ExecuteNonQuery();

ArticleContent would be the string with the japanese characters. ArticleContent将是带有日语字符的字符串。

My database was created on a MS SQL Server 2014 and I'm using Visual Studio 2015 to write this small application. 我的数据库是在MS SQL Server 2014上创建的,我正在使用Visual Studio 2015编写此小型应用程序。

You have to use the Unicode supporting nvarchar data types. 您必须使用支持nvarchar数据类型的Unicode。 According to MSDN : 根据MSDN

If you store character data that reflects multiple languages, always use Unicode data types (nchar, nvarchar, and ntext) instead of the non-Unicode data types (char, varchar, and text). 如果存储反映多种语言的字符数据,请始终使用Unicode数据类型(nchar,nvarchar和ntext),而不要使用非Unicode数据类型(char,varchar和text)。

If you want to use the full UTF-8 code page, you need to use the nvarchar data type. 如果要使用完整的UTF-8代码页,则需要使用nvarchar数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM