• .net操作mysql中文字符乱码的问题


    //写入数据库时进行转换
            public string GB2312_ISO8859(string write)
            {
                //声明字符集
                System.Text.Encoding iso8859, gb2312;
                //iso8859
                iso8859 = System.Text.Encoding.GetEncoding("iso8859-1");
                //国标2312
                gb2312 = System.Text.Encoding.GetEncoding("gb2312");
                byte[] gb;
                gb = gb2312.GetBytes(write);
                //返回转换后的字符
                return iso8859.GetString(gb);
            }

            //读出时进行转换
            public string ISO8859_GB2312(string read)
            {
                //声明字符集
                System.Text.Encoding iso8859, gb2312;
                //iso8859
                iso8859 = System.Text.Encoding.GetEncoding("iso8859-1");
                //国标2312
                gb2312 = System.Text.Encoding.GetEncoding("gb2312");
                byte[] iso;
                iso = iso8859.GetBytes(read);
                //返回转换后的字符
                return gb2312.GetString(iso);
            }

            //批量数据转换
            //其实就是将dataset的内容读出到xml文件,然后再输出
            public DataSet ISO8859_GB2312(DataSet ds)
            {
                string xml;
                xml = ds.GetXml();
                ds.Clear();
                //声明字符集
                System.Text.Encoding iso8859, gb2312;
                //iso8859
                iso8859 = System.Text.Encoding.GetEncoding("iso8859-1");
                //国标2312
                gb2312 = System.Text.Encoding.GetEncoding("gb2312");
                byte[] bt;
                bt = iso8859.GetBytes(xml);
                xml = gb2312.GetString(bt);
                ds.ReadXml(new System.IO.StringReader(xml));
                return ds;
            }

  • 相关阅读:
    CentOS_关机与重启命令详解
    去除ArrayList重复的对象
    单项设计模式
    死循环的应用
    java学习心得-面向对象与面向过程
    计算机使用个人经验及日常维护
    linux操作系统简介
    集合
    项目学习4
    周末总结
  • 原文地址:https://www.cnblogs.com/im/p/1151309.html
Copyright © 2020-2023  润新知