开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜