当我在Visual Studio中编码时,我的查询没有给出正确的结果,但是当我在MySql Workbench中尝试它时,它工作正常。有人能帮助我吗?
MySqlCommand cmd = null;
DataTable dataTable = new DataTable();
MySqlConnection mycon = new MySqlConnection("datasource=localhost; port=3306;username=root;password=; database = cmb;");
string se = "SELECT date AS 'Date', COUNT(case when patienttype = 'Child' then 1 else null end) AS `No of Child`, COUNT(case when patienttype = 'Adult' then 1 else null end) AS `No of Adult` FROM cmb.stat";
cmd = new MySqlCommand(se, mycon);
mycon.Open();
using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
{
da.Fill(dataTable);
}
dataGridView1.DataSource = dataTable;
dataGridView1.DataMember = dataTable.TableName;
mycon.Close();
VS Studio中的结果:
MySQL Workbench中的结果: