I'm trying to populate a chart and I need to grab data from an SQL Server database, I got my query and its quite simple but is made out of functions so the columns are all aliased, so when I try to add the columns to the reader I get no results, it just wont find them.
Here's my sample code...
- public static List<Work> ListNaturalResources(int directorateId)
- {
- var newList = new List<CasesWorkType>();
-
- using (var connection = new SqlConnection(Settings.Default.ServicesConnectionString))
- {
- connection.Open();
- string sql = "SELECT " +
- "MONTH(DateCreated) AS dMonth," +
- "YEAR(DateCreated) AS dYear," +
- "COUNT(*) AS dCount" +
- "FROM Works" +
- "WHERE DirectorateID = " + directorateId + " " +
- "GROUP BY " +
- "MONTH(DateCreated), " +
- "YEAR(DateCreated);";
-
- using (var command = new SqlCommand(sql, connection))
- {
- using (var reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
- var countPerDirectorate = new Work();
- countPerDirectorate. ?????? = reader["WorkDescription"].ToString();
- newList.Add(countPerDirectorate);
- }
- }
- }
- }
- return newList;
- }