Numeric to string problems.

T

Toble Rone

I have an application that needs to run in a server with specific regional
settings (South America). In some part of the code, i'm retrieving values
like "25,94" (that means... 25 as the integer part, 94 as the decimal
part.... using a ",").

The problem is that when i concatenate those values to build another sql
query, like an insert.... the "," is completely messing up the query.

How can i convert those values to use a "." instead... without using dirty
things like replacing "," by "."?

tnx.
 
C

Cor

Hi,

The first advice is use command.parameters instead of concatenating values
to a select statement. (I did not try this in this case, but it seems to me
the normal solution for this question)

Cor
 
A

Armin Zingler

Toble Rone said:
I have an application that needs to run in a server with specific
regional settings (South America). In some part of the code, i'm
retrieving values like "25,94" (that means... 25 as the integer part,
94 as the decimal part.... using a ",").

The problem is that when i concatenate those values to build another
sql query, like an insert.... the "," is completely messing up the
query.

How can i convert those values to use a "." instead... without using
dirty things like replacing "," by "."?

First, convert the string to a Decimal or Double. Use Decimal.Parse or
Double.Parse. If the string is in a format different from the current
regional settings, you can specify a second arg.

In an SQL query, use the Parameters property to pass the Decimal/Double
value. It does the formatting for you.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top