473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Decimal comma / point problem in sql

I think I've a simple question.

I'm using the datatype "decimal". I need to build a sql - insert
statement to save something in the database. But the problem is that the
decimal - datatypes are written with a comma " , " and not " . ".

So when I make the string:
--
dim decimalvariable as decimal
sql = "insert into table(decimalthing) values(" & decimalvariable & ")"
--
while decimalvariable is 10,12
my sql string will be:

"insert into table(decimalthing) values(10,12)"

So the sql statement is wrong because it thinks you want to insert 2
variables 10 and 12.

What can I do to make it "insert into table(decimalthing) values(10.12)" ?

PS: I'm living in Europe, we usually write decimals with a comma.
Dec 21 '05 #1
6 25379
Tommy DN wrote:
I think I've a simple question.

I'm using the datatype "decimal". I need to build a sql - insert
statement to save something in the database. But the problem is that the
decimal - datatypes are written with a comma " , " and not " . ".

So when I make the string:
--
dim decimalvariable as decimal
sql = "insert into table(decimalthing) values(" & decimalvariable & ")"
--
while decimalvariable is 10,12
my sql string will be:

"insert into table(decimalthing) values(10,12)"

So the sql statement is wrong because it thinks you want to insert 2
variables 10 and 12.

What can I do to make it "insert into table(decimalthing) values(10.12)" ?

PS: I'm living in Europe, we usually write decimals with a comma.


There may be a way to do this using culture that I'm not aware of.
You'll need a smarter man like Herfried to answer that. I would do this
like by just converting it to a string and replacing the "," with "."

Chris
Dec 21 '05 #2
use a parameter
"Tommy DN" <no****@nospam.com> wrote in message
news:vK******************************@scarlet.biz. ..
I think I've a simple question.

I'm using the datatype "decimal". I need to build a sql - insert statement
to save something in the database. But the problem is that the decimal -
datatypes are written with a comma " , " and not " . ".

So when I make the string:
--
dim decimalvariable as decimal
sql = "insert into table(decimalthing) values(" & decimalvariable & ")"
--
while decimalvariable is 10,12
my sql string will be:

"insert into table(decimalthing) values(10,12)"

So the sql statement is wrong because it thinks you want to insert 2
variables 10 and 12.

What can I do to make it "insert into table(decimalthing) values(10.12)" ?

PS: I'm living in Europe, we usually write decimals with a comma.

Dec 21 '05 #3
Tommy,

If you can see the Christmas wishes that you will see how international this
newsgroup is. The English language uses a dot as decimal seperator, all
other European languages a comma even in America and Africa. While in
Europe we use the dot as seperator as well. British and Irish people live as
well in Europe do you know.

However for SQL we use in Net parameters.

In this sample it is showed with a datetime because that is mostly the most
difficult to understand in these question, however it is the same for a
decimal.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

In your case of course instead of CDate, CDec

There are more parameter samples on our website.

I hope this helps,

Cor
Dec 21 '05 #4
Tommy DN wrote:
I think I've a simple question.
albeit a religious one, as it seems... :-D
I'm using the datatype "decimal". I need to build a sql - insert
statement to save something in the database. But the problem is that the
decimal - datatypes are written with a comma " , " and not " . ".

So when I make the string:
--
dim decimalvariable as decimal
sql = "insert into table(decimalthing) values(" & decimalvariable & ")"
--
while decimalvariable is 10,12
my sql string will be:

"insert into table(decimalthing) values(10,12)"

So the sql statement is wrong because it thinks you want to insert 2
variables 10 and 12.

What can I do to make it "insert into table(decimalthing) values(10.12)" ?

PS: I'm living in Europe, we usually write decimals with a comma.


You may as well use the InvariantCulture property of the CultureInfo
class:

Const SQL_INSERT As String = "insert into " _
& "table(decimalthing) values({0})"

Dim D As Decimal = 10.12D
Dim SQL As String
'...
SQL = String.Format(SQL_INSERT, _
D.ToString(System.Globalization.CultureInfo.Invari antCulture) )

HTH.

Regards,

Branco.

Dec 21 '05 #5
International stuff can be a pain to work with :-)

As Greg said, a parameter is the way to go. Don't use concatenation to build
sql strings like you do below since they are vulnerable to sql injection
attacks (I'm assuming that the actual decimal value will come from a textbox
or similar). Check the docs for SqlParameter.

/claes
"Tommy DN" <no****@nospam.com> wrote in message
news:vK******************************@scarlet.biz. ..
I think I've a simple question.

I'm using the datatype "decimal". I need to build a sql - insert
statement to save something in the database. But the problem is that the
decimal - datatypes are written with a comma " , " and not " . ".

So when I make the string:
--
dim decimalvariable as decimal
sql = "insert into table(decimalthing) values(" & decimalvariable & ")"
--
while decimalvariable is 10,12
my sql string will be:

"insert into table(decimalthing) values(10,12)"

So the sql statement is wrong because it thinks you want to insert 2
variables 10 and 12.

What can I do to make it "insert into table(decimalthing) values(10.12)" ?

PS: I'm living in Europe, we usually write decimals with a comma.

Dec 22 '05 #6
Branco Medeiros wrote:
Tommy DN wrote:
I think I've a simple question.

albeit a religious one, as it seems... :-D

I'm using the datatype "decimal". I need to build a sql - insert
statement to save something in the database. But the problem is that the
decimal - datatypes are written with a comma " , " and not " . ".

So when I make the string:
--
dim decimalvariable as decimal
sql = "insert into table(decimalthing) values(" & decimalvariable & ")"
--
while decimalvariable is 10,12
my sql string will be:

"insert into table(decimalthing) values(10,12)"

So the sql statement is wrong because it thinks you want to insert 2
variables 10 and 12.

What can I do to make it "insert into table(decimalthing) values(10.12)" ?

PS: I'm living in Europe, we usually write decimals with a comma.

You may as well use the InvariantCulture property of the CultureInfo
class:

Const SQL_INSERT As String = "insert into " _
& "table(decimalthing) values({0})"

Dim D As Decimal = 10.12D
Dim SQL As String
'...
SQL = String.Format(SQL_INSERT, _
D.ToString(System.Globalization.CultureInfo.Invari antCulture) )

HTH.

Regards,

Branco.


OK, I've converted the decimal variables with
System.Globalization.CultureInfo.InvariantCulture and it works.

Thanks,
Tommy DN.
Dec 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kim Bundgaard | last post by:
Hi Any suggestion would be fine. I have installed DB2 Connect EE V8.1 (fixpak 4) at two different Windows 2000 Servers, both have the same regional settings. I am connecting to the same DB2...
6
by: ibiza | last post by:
Hi all, I've binded some data from a DB in a gridview and one of the values is a float. Even if the flot is represented as 4.2 in the DB, it is rendered as 4,2 in the gridview, with a comma....
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
1
by: Twanne | last post by:
Hi, I've got some code in VBA where I calculate some numbers. Now some of them are large decimal numbers like -6,3216324E03. So in scientific notations. Now I need to add them to a table with an...
1
by: Joza | last post by:
Hi everybody! I have question about setting decimal symbols... In some countries, for example in my country we use comma for decimal symbol, but in in some other countries it is decimal point....
2
by: KiP.Kolodziejczyk | last post by:
I 'd like to insert (via "bulk insert") between 10-20 files (about 300MB each) into one table. The problem is that in input files decimal point is written as "," and without leading zeros (i.e.:...
2
by: nomad | last post by:
Hi, I was wondering how I would be able to remove a decimal point from a string value i.e. 10000.0 to 10000. Appreciate any help on this.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.