Foreword:
There is a requirement change, which requires changing all data in a table from Simplified Chinese to Traditional Chinese. The data in the table is not much, about 500. There are probably several ideas:
1. Manual translation, and then use tools such as Navicat to directly replace text (it’s okay to have more of the same text, but it’s still uncomfortable to have less) 2.
Adjust the public translation interface, and then use ORM to save (most translation interfaces are charged)
3 .Directly use program translation, and then use ORM to save
The third method is more convenient. I checked it and found that it can be achieved through VB method (.Net core cannot be used) and loading a dll that converts Simplified and Traditional Chinese.
Get converter
The second method used here, but you don’t need to download the dll, you can get it directly from NuGet. The
method of use is also very simple, just call the conversion method.
To convert table data
Here is an example of converting traditional Chinese characters to simplified characters (and vice versa).
The ORM framework here can use any one. In the example, SqlSugar is used.
There is an existing table
. Use DbFirst to specify the table name to directly create a class file
to directly obtain the collection and modify it. properties, then save and execute
SqlSugarClient client = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "server=.;database=XXXX;uid=XXXX;pwd=XXXXXX;",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true
});
List<Sample> samples = client.Queryable<Sample>().ToList();
samples.ForEach(item=> {
item.col1 = ChineseConverter.Convert(item.col1, ChineseConversionDirection.TraditionalToSimplified);
item.col2 = ChineseConverter.Convert(item.col2, ChineseConversionDirection.TraditionalToSimplified);
item.col3 = ChineseConverter.Convert(item.col3, ChineseConversionDirection.TraditionalToSimplified);
});
client.Updateable<Sample>(samples).WhereColumns(it => new {
it.Id }).ExecuteCommand();
client.Close();
Check the database:
The fields were changed to simplified Chinese, but some garbled characters were caused by the wrong character set setting of the database (not a problem with the program).