INSERT of a Decimal using VB.NET

D

DraguVaso

Hi,

I want to insert some recors in an Sql Server which have some decimal
values:

For exemple: I have a vairable called sngPi = 3,1415 (european notation:
"," = comma)

When I build my SQL-statement dynamically like:
strSQL = "INSERT INTO tblBlabla (MyName, Pi) VALUES ('Pieter', " & sngPi &
")"

But: the result is offcourse: "INSERT INTO tblBlabla (MyName, Pi) VALUES
('Pieter', 3,1415)" which gives me an error that I want to insert 2 values,
and have only one field.

So I actually should insert it as ""INSERT INTO tblBlabla (MyName, Pi)
VALUES ('Pieter', 3.1415)" to work fine.

I could 'build' my variable as a string by taking the first part,
concattenating a point, and than concatenate the last part, but I guess
there must be a nicer and better way to work arround this problem. I want a
solution that works in every case, independent of the regional settings on
the application-pc and the sql-server.

Anybody any idea?

Thansk a lot in advance!

Pieter
 
A

Armin Zingler

DraguVaso said:
When I build my SQL-statement dynamically like:
strSQL = "INSERT INTO tblBlabla (MyName, Pi) VALUES ('Pieter', " &
sngPi & ")"

But: the result is offcourse: "INSERT INTO tblBlabla (MyName, Pi)
VALUES ('Pieter', 3,1415)" which gives me an error that I want to
insert 2 values, and have only one field.

So I actually should insert it as ""INSERT INTO tblBlabla (MyName,
Pi) VALUES ('Pieter', 3.1415)" to work fine.

Use the Parameters property of the SQLCommand object.
 
C

CJ Taylor

Use a data adapter or parameterized sql command object, it will take care of
the conversion for you.
 
M

MSN NewsGroups

This may not be an ideal solution but here's one way you could do it:
sngPi.ToString.Replace(",", ".")
 

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