views:

73

answers:

3

The problem is that in c# I can't subtract the objects, so I need to figure out how to get the integers out of them and then do the arithmetic? Here's the code.. what am I missing?

dsfDataSet.itemTotals.Compute( "SUM(priceSum)", String.Empty ) - dsfDataSet.discountItems.Compute("SUM(totDiscount)", String.Empty)
+1  A: 

If you know the data is integer, you should use Convert.ToInt16 or similar functions to extract the integers. Be sure to add additional exception handling, in case the data turns out to be non integer.

DevByDefault
A: 

What is the return type of your Compute function? Object? Or a defined type?

If defined, you CAN overload the '-' operator, you know? Otherwise, what is stopping you from creating a method that take those two structures and return the integer result you need? Why must it be with '-' ?

Leahn Novash
compute is defined already to return type object. is there some way to adjust that?
kristofer
Then I suggest you to create a function that will take two objects, check if both are integers, and return the difference, or throw an exception otherwise.
Leahn Novash
+1  A: 

you can use int.TryParse as the output of DataTable.Compute is object

int priceSum,totDiscount;

if(int.TryParse(dsfDataSet.itemTotals.Compute( "SUM(priceSum)", String.Empty ).ToString(),out priceSum))
{
  if(int.TryParse(dsfDataSet.discountItems.Compute("SUM(totDiscount)", String.Empty).ToString(),out totDiscount))
  {
    priceSum - totDiscount;
  }
}
Ahmed Said