Hello, I have the following code:
if (dataTable.Columns.Count > 1) { strXML = ChartFileNameandPath(chartType) + @"?dataXML=<graph caption='Report ; Summary' subcaption='" + ReportName(reportType) + "' xAxisName='Line Number' yAxisName='Pounds made' rotatelabels='1' slantlabels='1' showNames='1' showvalues='0' numberPrefix='$' exportenabled='1' exportAtClient='1' exportHandler='fcExporter1' exportFormats='PNG=Save as PNG' >"; //Getting the Subtotal of PoundsMade based on the Line Number column //C# linq query if (reportType == ReportEnums.Clientsdata) { var query = from row in dataTable.AsEnumerable() group row by row.Field<string>("ClientName") into grp orderby grp.Key select new { Clientname = grp.Key, TotalAmountSpent = grp.Sum(r => r.Field<int>("TotalAmountSpent")) //error here, specified cast is not valid }; foreach (var grp in query) { strXML = strXML + "<set name='" + grp.Clientname.ToString() + "' value='" + grp.TotalAmountSpent.ToString() + "'/>"; } }
I get a error "Specified cast is not valid"
Part of my store procedure where I'm grabbing it from is:
SELECT ClientName, Mem_Name, Mem_Address, Mem_city, Mem_state, Sum(mv.AmountSpent) as TotalAmountSpent, (Sum(mv.AmountSpent)/ (CAST(s.TotalBusinessSales as decimal)) * 100) as PercentAmountSpent
My question is: Am I getting an error because of TotalAmountSpent is an alias?
Thanks,
N