Hi everybody, I'm trying to build a chart in asp.net. For that I'm trying to cast the result of my linq query in int type but I have an error saying that only int, string, decimal type can be use. I don't understant what happened. Is someone have an idea ?? Here is my code :
- protected void GetChartData2()
- {
- Series series = Chart2.Series["Series2"];
- series.Color = System.Drawing.Color.Blue;
-
- using (Context db = new Context())
- {
- if (db.InfoLivraison.Count() > 0)
- {
- DateTime end = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));
- DateTime start = end.AddDays(-7);
-
- List<InfoLivraison> listCA = (from infoLivCA in db.InfoLivraison
- where infoLivCA.date_command2 >= start && infoLivCA.date_command2 <= end
- select infoLivCA).ToList();
-
- DataTable dt2 = ToDataTable<InfoLivraison>(listCA);
-
- DataTable dtjour = dt2.DefaultView.ToTable("Jours7CA", true, "date_command2");
- DataTable dtMontant = dt2.DefaultView.ToTable("Montants7CA", true, "montantCommande");
-
- if (dtjour.Rows.Count != 0)
- {
-
- for (int i = 0; i < dtjour.Rows.Count; i++)
- {
- DateTime selectedDate = Convert.ToDateTime(dtjour.Rows[i]["date_command2"]);
- string selectedDateStr = Convert.ToString(selectedDate);
-
- for(int j=0;j<dtjour.Rows.Count;j++)
- {
- var linqSum = db.InfoLivraison.GroupBy(a => selectedDate)
- .Select(b => new { total = b.Sum(a => Convert.ToDecimal(a.montantCommande))});
-
- series.Points.AddXY(selectedDate.ToString("dd/MM/yyyy"), linqSum);
- }
- }
- }
- }
- }
- }
Thanks for your help