Click here to Skip to main content
13,703,000 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I'm trying to calculate the sum of MySQL data rows column table (ColumnSum) where data in columnkey = 999 using c# with entities query !
error shows at line
int TimeFab = int.Parse(item.ColumnSum);
:
Input string was not in a correct format.

What I have tried:

DatabaseEntities  ET = new DatabaseEntities  () ;
int TimeFabricate =0;
var query = from Time in ET where Time.Columnkey == "999"  select new { Time.ColumnSum };

var result = query.ToList();

foreach (var item in result)
{
    int TimeFab = int.Parse(item.ColumnSum);
   TimeFabricate +=  TimeFab;

              }

MessageBox.Show(TimeFabricate.ToString());
Posted 9-Nov-17 21:50pm
Updated 9-Nov-17 22:16pm
Comments
CHill60 10-Nov-17 4:05am
   
If you debug your code what is in item.ColumnSum - I suspect null. Try using TryParse instead of Parse
EM_Y 10-Nov-17 4:15am
   
I resulted the problem ,I converted my data to integer while I have float numbers :thank you for your help

float TimeFab = float.Parse(item.ColumnSum);

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I resulted the problem ,I converted my data to integer while I have float numbers :thank you for your help

float TimeFab = float.Parse(item.ColumnSum);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05-2016 | 2.8.180906.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100