Formatting numbers

  • Thread starter Thread starter Highpotech
  • Start date Start date
H

Highpotech

i'am using the following statement to format a aql string
sql=string.format("INSERT INTO werkboek VALUES {0}, {1}....;"
m_WNR, m_Aantal...)
Aantal is a decimal and evaluates into 2.5D. Evalutating the sql strin
i get:
"INSERT INTO werkboek VALUES 7, 2,5....;" 'ATT there is a decimal
placeholder where i don't want it
I've changed te code for the placeholder {1} to {1:#.00} in order to
change te output to 2.5 instead of 2,5 but no luck.
Is there a other way to change ste code to get te requered output te
read:
"INSERT INTO werkboek VALUES 7, 2.5....;"

Thanks in advance
Alexander M. Polak
mailto:[email protected] mail is certified Virus
Free.Checked by AVG anti-virus system (http://www.grisoft.com).Version:
6.0.742 / Virus Database: 495 - Release Date: 19-08-2004
 
Could you not use a paramterised query to insert your
values into your INSERT statement instead of a string
with them already embedded. Plus you get the advantage
of SQL server already having an execution plan for the
query, which will make it faster.

cmd = "INSERT INTO werkboek VALUES (@P1, @P2)

da.InsertCommand.CommandText = cmd
da.InsertCommand.Parameters.Add("@P1", SqlDbType.Decimal)
da.InsertCommand.Parameters.Add("@P2", SqlDbType.Decimal)

Or atleast something like it.

Jason.
 
using parameters is still likely to be a better
solution, even if you then have to solve other problems - embedding
literals in SQL statements comes with all kinds of problems. (SQL
injection attacks, determining the input format for things like dates,
numbers etc, performance, to name just a few.)


Rather then using an other approch I'like to use solve the problem at hand

On way to resove the problem might lay in using InvariantCulture, but i'm
having a little problem in how to use this.
Any suggestions there??
 
Hi,

I am not sure if I follow your reasoning, however, using parameters should
be *the* solution and not building a string dynamically.
Anyway, if you insist on using the later approach consider something like:
string.Format("...{0}...", ...,
decimal.ToString(CultureInfo.InvariantCulture), ...)
 
Will try that tanks
Alexander M. Polak at Highpotech IT

Miha Markic said:
Hi,

I am not sure if I follow your reasoning, however, using parameters should
be *the* solution and not building a string dynamically.
Anyway, if you insist on using the later approach consider something like:
string.Format("...{0}...", ...,
decimal.ToString(CultureInfo.InvariantCulture), ...)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Highpotech said:
using parameters is still likely to be a better
solution, even if you then have to solve other problems - embedding
literals in SQL statements comes with all kinds of problems. (SQL
injection attacks, determining the input format for things like dates,
numbers etc, performance, to name just a few.)


Rather then using an other approch I'like to use solve the problem at hand

On way to resove the problem might lay in using InvariantCulture, but i'm
having a little problem in how to use this.
Any suggestions there??
 
Back
Top