Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6981245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:07:54+00:00 2026-05-27T18:07:54+00:00

DataTable dtStock = new DataTable(); DataColumn dcTotalCases = new DataColumn(TotalCases); dcTotalCases.DataType = System.Type.GetType(System.Int32); dcTotalCases.ReadOnly

  • 0
DataTable dtStock = new DataTable();
DataColumn dcTotalCases = new DataColumn("TotalCases");
dcTotalCases.DataType = System.Type.GetType("System.Int32");
dcTotalCases.ReadOnly = false;
dtStock.Columns.Add(dcTotalCases);

Method 1

int sum = Convert.ToInt32(dtStock.Compute("Sum([TotalCases]) ", "[TotalCases] <> ''"));

When I use this method, I get an error

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

Method 2

int sum = Convert.ToInt32(dtStock.Compute("SUM(Convert([TotalCases], 'System.Int32'))", "");

When I use this method, I get an error

Syntax error in aggregate argument: Expecting a single column argument
with possible ‘Child’ qualifier.

Please help me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:07:55+00:00Added an answer on May 27, 2026 at 6:07 pm

    I believe method #1 should work – just don’t compare your INT column to an empty string!!

    So use something like this:

    int sum = Convert.ToInt32(dtStock.Compute("Sum(TotalCases)", "[TotalCases] > 0"));
    

    or

    int sum = Convert.ToInt32(dtStock.Compute("Sum(TotalCases)", "[TotalCases] IS NOT NULL"));
    

    or whatever you need – just don’t use [TotalCases] <> '' since that compares an INT to an empty string – and that’s not going to work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two datatable , first contain DataTable dtMaterialStatement = new DataTable(); dtMaterialStatement.Columns.Add(new DataColumn(MaterialNo,
DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn(gridColumn1, typeof(bool))); I was expecting the result of
First Datatable is dt var dt = new DataTable(); dt.Columns.Add(ID); dt.Columns.Add(First Name); dt.Rows.Add(1,name1); dt.Rows.Add(6,name6);
DataTable dt1 = new DataTable(); //I made this as a backup //add 3 columns
DataTable dt = new DataTable(); dt.Columns.Add(col1); dt.Columns.Add(col2); dt.Columns.Add(col3); dt.Columns.Add(col4); dt.Columns.Add(col5); dataGridView1.DataSource = dt; dataGridView1.Columns.RemoveAt(3);
For example: DataTable table = new DataTable() { Columns = new DataColumnCollection( { new
I have a datatable in windows form and I want to add a new
DataTable tempTable = new DataTable; . . . tempTable = getCustomerTable(); In this case,
we have a datatable st with two columns word and binary void replace() {
I have a DataTable and when I alter (add,modifiy..ect) it wont reflect on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.