【发布时间】:2016-12-03 15:50:28
【问题描述】:
这是我的 sql 查询
select Month,count(id) transactions from `tbl_test` where id=" + id + " and Month is not NULL and Year = " + Convert.ToInt32(currentYear) + " group by Month;
月份是 varchar 和 id 是 int 我正在使用 mysql。
将其填充到数据表中
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
我得到的结果是这样的
Month transactions
May 122
December 178
而我想要的结果是这样的
Month transactions
January 0
February 0
March 0
April 0
May 122
June 0
July 0
August 0
September 0
October 0
November 0
December 178
我创建了另一个包含所有月份的表并尝试加入 2。但没有用(我猜是因为 sql 语句中的 where 子句)。请帮忙。
PS:我不希望更改查询,而是使用前端编码 (C#) 来插入 DataTable。
【问题讨论】:
-
你使用 MySQL 还是 MariaDB。 MariaDB 有一个非常好的序列引擎来做这样的事情
-
我正在使用 MySql。
标签: c# mysql sql asp.net c#-4.0