连接字符串的charset 仍然写utf8
查询DataTable时先设置一下编码可查询成功,不过需要两次查询
try
{
DataTable dt = new DataTable();
using (MySqlConnection conn = new MySqlConnection(Constants.MYSQL_STR))
{
conn.Open();
MySqlCommand cmd2 = new MySqlCommand("set names utf8", conn);
cmd2.ExecuteNonQuery();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from ypf_comment where cid = @source";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new MySqlParameter("@source", 2));
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
sda.Fill(dt);
conn.Close();
}
}
catch (MySqlException ex){ }