0

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?

JL.
  • 78,954
  • 126
  • 311
  • 459

1 Answers1

2

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
  • 687,336
  • 108
  • 737
  • 1,005