加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]解决C#中文乱码问题

(2018-02-26 16:16:11)
标签:

转载

分类: 网站博客查询

文章来源:网络


using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySQLDriverCS;
using System.Data;
using System.Configuration;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();


    }
    private void BindData()
    {
        string constr = ConfigurationManager.AppSettings["JICQMySql"];
        MySQLConnection conn = null;
        // conn = new MySQLConnection(new MySQLConnectionString("localhost", "protege_db", "root", "sdie?!3406").AsString);
        conn=new MySQLConnection(constr);
        //本地数据库 数据库名字 用户名root 密码
        conn.Open();
        MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
        commn.ExecuteNonQuery();       //设置set names gb2312   解决乱码
        string sql = "select * from animal";
        MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
        DataSet ds = new DataSet();
        mda.Fill(ds, "tb");
        this.gwShow.DataSource = ds.Tables["tb"];
        gwShow.DataBind();
        conn.Close();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MySQLConnection conn = null;
        conn = new MySQLConnection(new MySQLConnectionString("localhost", "protege_db", "root", "sdie?!3406").AsString);
        conn.Open();
        MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
        commn.ExecuteNonQuery();
        MySQLCommand comm = new MySQLCommand(string.Format("insert into animal (frame,frame_type,slot,facet,is_template,value_index,value_type) values ('{0}','{1}','{2}',1,1,1,1)", tbName.Text.Trim(), tbAddress.Text.Trim(), tbTelephone.Text.Trim()), conn);
        comm.ExecuteNonQuery();
        conn.Close();
        BindData();
    }

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有