I’m running the query below :-
var Values = from data in DtSet.Tables["tblCosts"].AsEnumerable()
group data by new
{
InvNo = data.Field<double>("InvoiceNo"),
AccRef = data.Field<double>("SiteRefNum"),
}
into g
select new
{
Code = "1",
InvType = "I",
Account = g.Key.AccRef,
InvNo = g.Key.InvNo,
ChargeTotal = g.Sum(d => d.field<double>("Charge")
};
Due to the way the data is imported into the datatable (from Excel) sometimes the datatype of AccRef is double and sometimes it’s string. Is there a way to overcome this at runtime, as I’d prefer to not have the user modify the source data in Excel before importing.
You can use
Convert.ToDoublewith objects, so it should work for double and for string:Of course that works only if
SiteRefNumis actually convertable to adouble.