Link to home
Start Free TrialLog in
Avatar of MrMay
MrMay

asked on

c# coding help

I need some help.
Can someone please take a look at the attached and please tell me what I need to adjust?
please & thank you.

This bit of code goes throught two access tables (inner joint) and returns the total number of hours worked by a mechanic
Capture.JPG
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

I removed my bad post. I had no way of deleting it.
Avatar of Fernando Soto
Hi MrMay;

Try and placing everything after (int) in its own set of parentheses.

newNum1 = (int)( ... );
Avatar of MrMay
MrMay

ASKER

I tried Fernando... no difference.
This code works if I replace SUM with COUNT in the sql query.  But I don't want a count in this situation but a SUM.
An index operation (i.e. the square brackets) has higher precedence than a cast (i.e. the (int) part), so you shouldn't need the additional parentheses that Fernando suggests...though adding them won't hurt anything. Are you certain that the think inside the column is actually of type int? Does the error go away if you change the code to use the Convert class instead?

e.g.

newNum1 = Convert.ToInt32(ds.Tables["TaskLabor"].Rows[ds.Tables["TaskLabor"].Rows.Count - 1][0]);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrMay

ASKER

thanks for the post kaufmed that worked. The only problem that I'm running into now is if there is a return of null (zero) I still get the same error msg.
So lets say hrs of Mechanic1 is 5.. i get that return. but lets say mechanicB has worked no hrs.. it crashes on me.
How do i adjust that so if there is a return of null (nothing) it returns a zero.
thank u all.