Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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

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

C#
float TimeFab = float.Parse(item.ColumnSum);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900