简体   繁体   English

在SQL Server 2008中存储其他语言并取回

[英]Store other languages in SQL Server 2008 and retrieve back

I am using an Excel sheet to upload my records into a database. 我正在使用Excel工作表将我的记录上传到数据库中。 Some columns in the Excel sheet are not in English language. Excel工作表中的某些列不是英语。 How can I read and store the other language into the database? 如何阅读其他语言并将其存储到数据库中?

I can perfectly read and store English in database. 我可以完美地阅读英语并将其存储在数据库中。 I searched google for some options. 我在Google上搜索了一些选项。 I tried the following code to convert it to UTF8 and store in database. 我尝试了以下代码将其转换为UTF8并存储在数据库中。 I database I am using nvarchar(MAX) . 我在数据库中使用nvarchar(MAX)

byte[] bytes = Encoding.UTF8.GetBytes(dsExcel.Tables[0].Rows[i][7].ToString());
string myString = Encoding.UTF8.GetString(bytes);

When it gets stored in database I can see only ?????????? 当它存储在数据库中时,我只能看到?????????? in the column. 在列中。 If I take input from a textbox and store then I don't have any problem. 如果我从文本框中输入内容并存储,那么我没有任何问题。

Please help - what can be done? 请帮忙-该怎么办?

I want to store and retrieve the same language string from the database. 我想从数据库中存储和检索相同的语言字符串。

Your problem is probably the UTF8 encoding you are using. 您的问题可能是您使用的UTF8编码。 You need to use Unicode. 您需要使用Unicode。

But it seems unnecessary to use the Encoding type: why not just get the string from the DataTable row? 但是似乎没有必要使用Encoding类型:为什么不只从DataTable行中获取字符串? By default the CLR treats strings as unicode. 默认情况下,CLR将字符串视为unicode。

string myString = dsExcel.Tables[0].Rows[i][7].ToString();

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

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