1
DataTable tblnew;
tblnew= dataSet.Tables[0];

// Declare an object variable.
object sumObject;
sumObject = tblnew.Compute("Sum(Debit)", "");

Label lbl = new Label();
lbl.Text = sumObject.ToString();

Error: Invalid usage of aggregate function Sum() and Type: String.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • Please stop using datatables, it's old, try Entity Framework with Linq – Marco Salerno Mar 09 '18 at 10:29
  • @Marco Salerno not everyone can use EF and there are plenty of reasons not to even if you can. – Crowcoder Mar 09 '18 at 10:35
  • what is the data type of Debit column? – Aman B Mar 09 '18 at 10:36
  • I'm curious to read the reasons – Marco Salerno Mar 09 '18 at 10:36
  • @Crowcoder it's true not everyone can use it. But would you mind sharing some of these reasons not to use EF? – Alisson Reinaldo Silva Mar 09 '18 at 10:38
  • @Aman B => datatype of debit column was defined as string., now i had change that to int.. and error is resolved. thanku. – Mamta Apraj Mar 09 '18 at 10:47
  • @Alisson sure, but not in an SO comment. I'll post back here after writing a blog post. I like EF but not globally, all the time. – Crowcoder Mar 09 '18 at 11:15
  • @Crowcoder it's ok not to like it globally, all the time. But you say there are plenty of reasons not to use it, and don't mention one or two at least. There is really no need to make a blog post to show some points (e.g performance if compared to other ORMs like Dapper). – Alisson Reinaldo Silva Mar 09 '18 at 12:03
  • @Alisson ok, 1. you can't run two or more async tasks on the same context simultaneously. 2. It is much harder to apply security when you don't want to open the entire database to CRUD operations. 3. Code first can build unexpected schemas, you have to go look at what was generated to make sure it is what you want. 4. ORMs are supposed to make it easier but when you need to tune and configure things (even simple things like precision and scale) it adds complexity that approaches diminishing return on why you are using an ORM in the first place. There's more but I'm out of room. – Crowcoder Mar 09 '18 at 13:11

0 Answers0