473,396 Members | 1,693 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.

INSERT of a Decimal using VB.NET

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

Nov 20 '05 #1
3 7927
Use a data adapter or parameterized sql command object, it will take care of
the conversion for you.
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:3f**********************@news.skynet.be...
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

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

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:3f**********************@news.skynet.be...
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

Nov 20 '05 #3
"DraguVaso" <pi**********@hotmail.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

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

Similar topics

9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
0
by: John D. | last post by:
I am having problems inserting Decimal values into a DB2 database via a .NET/C# application which is using an OdbcDataAdapter. Other field types such as VarChar, Int, Date, etc work ok, and I can...
4
by: G.Esmeijer | last post by:
Friends When I use a Querystring for insertdating data into a Tabel (going to SQLserver) the decimal pint changes to a comma. The result is that I get a system error (which I can understand) ...
1
by: ven | last post by:
hello i`m makin a asp.net service with database connection where i have an insert with decimal value, when i run my function i get this error : There are fewer columns in the INSERT statement...
2
by: Dot Net Daddy | last post by:
Hello, I cannot get the following Insert Command work. I get the error: Error converting data type varchar to numeric. Description: An unhandled exception occurred during the execution of...
1
by: Noppers | last post by:
I am trying to insert data into 2 tables, Order and Order_Item, in a transaction. Everything works fine if I only have 1 row in my objCartDT dataset. If I have only one row, the 2 tables are updated...
8
by: Santy | last post by:
Hello All, I am new to DB2, Currently i am using DB2 version 8.02 personal edition on Windows XP Professional. And Facing problem with rowlock in insert query. I have created a sample database...
0
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the...
5
by: maestroQC | last post by:
Hi, Its one of those days. I cannot solve this. Any help would be greatly appreciated! When I execute this: class Db(object): def insertAccount(self, date, accountNumber, description,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.