当前位置:Gxlcms > mysql > mysql-C#Mysqldatagridview控件列标题中文乱码问题

mysql-C#Mysqldatagridview控件列标题中文乱码问题

时间:2021-07-01 10:21:17 帮助过:19人阅读

datagridviewmysql中文乱码c#

用C#从Mysql中读取数据到datagridview控件中,结果列标题中文乱码,内容没事。代码如下:
string commstr = "SELECT Patient_ID as ID,NAME as 姓名,TARGET as 患侧,DIAGNOSIS as 诊断 FROM PatientInfo";
this.data_case.DataSource = DBOperate.DBOperate.selectData(commstr, 数据库.DBConnection.SqlConnstr);
int rows = this.data_case.RowCount - 1;
for (int i = 0; i < rows; i++)
{
if (this.data_case.Rows[i].Cells[2].Value.ToString() == "L")
this.data_case.Rows[i].Cells[2].Value = "左手";
else
this.data_case.Rows[i].Cells[2].Value = "右手";
}
列标题名称本来应该是ID 姓名 患侧 诊断 的,但出现了中文乱码。我在DOS下对MySQL进行数据库查询操作,同样查询命令"SELECT Patient_ID as ID,NAME as 姓名,TARGET as 患侧,DIAGNOSIS as 诊断 FROM PatientInfo"的标题是ID 姓名 患侧 诊断,没有乱码。这是哪里出了问题,要怎么解决呢?

人气教程排行