el ninho
el ninho

Reputation: 4233

How to be sure you sent proper decimal value?

On my developement PC, I Use US regional settings, so when I send from c#/asp.net to sql server stored procedure 200.00, it takes it as 200, but on production server, with other regional settings, it takes it as 20000, as decimal point is ",". Ok, I know I can replace it, but I need permanent solution, so my question is: Is there any way to be sure I sent decimal number, dependless of regional settings?

Upvotes: 0

Views: 277

Answers (2)

recursive
recursive

Reputation: 86094

It sounds like your problem is not with SQL Server, but with parsing decimals. Your question seems a little vague because the string formatting of an "actual decimal number" varies with locale. If you want to convert strings to decimals in a locale-invariant way, you can specify a format provider when you parse them.

For example:

decimal.Parse("20.000", 
    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

Upvotes: 2

D Stanley
D Stanley

Reputation: 152566

I'm guessing you're sending the value as a string, either as a VARCHAR parameter to a procedure or (more likely) by concatenating SQL.

In either case, the solution is the same - send numeric values as numeric types instead of strings, and/or use parameterized queries instead of concatenating strings to generate a SQL statement.

Upvotes: 1

Related Questions