请大家看看我的MySQL乱码问题
/// <summary>
/// 查询数据
/// </summary>
/// <param name= "sql "> </param>
public DataSet query(string sql)
{
this.openConn();
MySQLDataAdapter sqlDA = new MySQLDataAdapter( "set names gb2312 ", DBConn);
sqlDA = new MySQLDataAdapter(sql, DBConn);
DataSet ds = new DataSet();
sqlDA.Fill(ds, "message ");
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;
}
这是在DbManager类中的代码,包括了数据库的一些操作.
//拼装查询语句,绑定数据库
protected void GridView1_DataBind()
{
try
{
StringBuilder strCommand = new StringBuilder();
strCommand.Append( "select * from ygjnk_zd_jnlb ");
strCommand.Append( "where(1=1) ");
string str = strCommand.ToString();
//将查询结果放在DataSet结果集中
DataSet dr = dao.query(str);
&nb