Cast to Int and Decimal

R

RP

I want to Cast the following code lines.

[Cast To Int]
Product.ProductID = dvProduct[0]["ProductID"].ToString();

[Cast To Decimal]
Product.UnitPrice = dvProduct[0]["UnitPrice"].ToString();

dvProduct is a DataView.
 
M

Marc Gravell

Since it isn't clear what these values are, your best bet may be
Convert:
int prodId = Convert.ToInt32(dvProduct[0]["ProductID"]);
decimal unitPrice = Convert.ToDecimal(dvProduct[0]
["UnitPrice"]);

If the data-types are known to be OK, you might have been able to
simply cast directly:

int prodId = (int) dvProduct[0]["ProductID"];
decimal unitPrice = (decimal)
Convert.ToDecimal(dvProduct[0]["UnitPrice"];

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top