How can I use the type of a DataSet Table Column instead of converting it to a string first then back to a number?

I have a numeric column in a table in a dataset.  I want use that column data in an equation without pulling the value out into a local decimal.

decimal amount = decimal.Parse(segDS.Tables[0].Rows[0]["Annuity_Issued_Period"].ToString()) + decimal.Parse(lifeFitDS.Tables[0].Rows[0]["Annuity_Issued_Period"].ToString());

Open in new window


I'd prefer not to so do decimal.Parse on a ToString if I don't have to.
LVL 1
BruceAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Snarf0001Connect With a Mentor Commented:
sql numeric should map to a decimal, so all you should have to do is cast the value.

decimal amount = (decimal)segDS.Tables[0].Rows[0]["Annuity_Issued_Period"] + (decimal)lifeFitDS.Tables[0].Rows[0]["Annuity_Issued_Period"];

Open in new window


Note that this will fail if you're bringing back nulls though.
0
All Courses

From novice to tech pro — start learning today.