1
Answer

Cast var linq query in int issue

bani marc

bani marc

7y
240
1
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 :
 
  1. protected void GetChartData2()  
  2.         {  
  3.             Series series = Chart2.Series["Series2"];  
  4.             series.Color = System.Drawing.Color.Blue;  
  5.   
  6.             using (Context db = new Context())  
  7.             {  
  8.                 if (db.InfoLivraison.Count() > 0)  
  9.                 {  
  10.                     DateTime end = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));  
  11.                     DateTime start = end.AddDays(-7);  
  12.   
  13.                     List<InfoLivraison> listCA = (from infoLivCA in db.InfoLivraison  
  14.                                                   where infoLivCA.date_command2 >= start && infoLivCA.date_command2 <= end  
  15.                                                   select infoLivCA).ToList();  
  16.   
  17.                     DataTable dt2 = ToDataTable<InfoLivraison>(listCA);  
  18.   
  19.                     DataTable dtjour = dt2.DefaultView.ToTable("Jours7CA"true"date_command2");  
  20.                     DataTable dtMontant = dt2.DefaultView.ToTable("Montants7CA"true"montantCommande");  
  21.   
  22.                     if (dtjour.Rows.Count != 0)  
  23.                     {  
  24.   
  25.                         for (int i = 0; i < dtjour.Rows.Count; i++)  
  26.                         {  
  27.                             DateTime selectedDate = Convert.ToDateTime(dtjour.Rows[i]["date_command2"]);  
  28.                             string selectedDateStr = Convert.ToString(selectedDate);  
  29.   
  30.                             for(int j=0;j<dtjour.Rows.Count;j++)  
  31.                             {  
  32.                                 var linqSum = db.InfoLivraison.GroupBy(a => selectedDate)  
  33.                                     .Select(b => new { total = b.Sum(a => Convert.ToDecimal(a.montantCommande))});  
  34.   
  35.                                 series.Points.AddXY(selectedDate.ToString("dd/MM/yyyy"), linqSum);  
  36.                             }  
  37.                         }  
  38.                     }  
  39.                 }  
  40.             }  
  41.         }  
Thanks for your help 
Answers (1)