zoukankan      html  css  js  c++  java
  • 写入mssql出现乱码

    1、出现乱码的场景如下:

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------

    1)c#代码如下:

    private int InsertBaseReport(int year, long mainId, Guid? orgId, DateTime repordate, string indictorCode, string dataValue)
    {
    string insertSql =
    $"insert into T_Report_Base{year} (F_MainID,F_OrgID,F_ReportDate,F_IndicatorCode,F_Value,F_LastDateTime) " +
    $"values({mainId},'{orgId}','{repordate}','{indictorCode}','{dataValue}',getdate())";
    return db.Database.ExecuteSqlCommand(insertSql);
    }

    2)数据库字段设计F_Value类型varchar(100)

    3)结果:F_Value字段出现乱码

    2、解决方案:

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------

    1)c#代码修改如下:

    private int InsertBaseReport(int year, long mainId, Guid? orgId, DateTime repordate, string indictorCode, string dataValue)
    {
    string insertSql =
    $"insert into T_Report_Base{year} (F_MainID,F_OrgID,F_ReportDate,F_IndicatorCode,F_Value,F_LastDateTime) " +
    $"values({mainId},'{orgId}','{repordate}','{indictorCode}',N'{dataValue}',getdate())";
    return db.Database.ExecuteSqlCommand(insertSql);
    }

    2)数据库字段设计F_Value类型修改为nvarchar(100)

    3)  将控制面板中->区域 设置更改为中文(简体,中国)

  • 相关阅读:
    MySQL的复制原理及配置
    MySQL Partition分区扫盲
    SQLite3中自增主键
    SQLite3时间函数小结
    MySQL行级锁,表级锁,页级锁详解
    .vimrc & .bashrc 文件配置
    RecursiveDirectoryIterator目录操作类
    InnoDB外键使用小结
    Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
    关于友谊的天长地久的方法
  • 原文地址:https://www.cnblogs.com/anibei/p/10747584.html
Copyright © 2011-2022 走看看