SQL Decimal Issue
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?
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)
精彩评论