views:

69

answers:

1

I have an input string in the following format: 12.34

When I call this line:

db.AddInParameter(insertMessageDetailCommand, "AttachmentSize", System.Data.SqlDbType.Decimal  , Convert.ToDecimal(this.messageEnvelope.EnvelopeInfo.AttachmentSize));

I get an input string not in the correct format. The server I am deploying to have regional settings with a "," separator for decimals. But other production servers could have "." separators.

How can I pass this string value : 12.34 to this function so that it doesn't break, and its generic enough to withstand any regional setting you throw at it?

+2  A: 

Specify a culture when you parse the string to elliminate differences in server settings. You can use InvariantCulture, which uses period as decimal separator:

Convert.ToDecimal(this.messageEnvelope.EnvelopeInfo.AttachmentSize, CultureInfo.InvariantCulture)
Guffa
excellent thanks, that really cleared it up....
JL