473,699 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7954
Use a data adapter or parameterized sql command object, it will take care of
the conversion for you.
"DraguVaso" <pi**********@h otmail.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**********@h otmail.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**********@h otmail.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
3456
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, VARCHAR(10) WO.PROBLEMCODE, VARCHAR(8)
4
11965
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 14 (STDCOST). ---End Error Msg--- The STDCOST is set to decimal (28,14) and is a formatted in Access as a number, single with 14 decimal. I don't know why I would be getting a Type
0
2270
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 insert literal values into a decimal field, but any attempt to insert a decimal field via an OdbcParameter causes a System.InvalidOperationException ("The connection is dead") to be thrown by the DbDataAdapter.Update method. The ODBC driver is...
4
8225
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) sSQL = "INSERT A,B INTO TABEL VALUES (aValue, BValue"); where A ="aaa" and B = 12.5
1
7654
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 than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement this is my insert : Dim queryString2 = "INSERT INTO
2
6210
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 the current web request. Please review the stack trace for more information about the error and where it originated in the code.
1
5843
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 as expected. But if I have more than one row in the objCartDT, something fails, and I can't figure out what (but I suspect it has to do with the params in conjunction with "cmdNewOrder_Items.ExecuteNonQuery();" and the looping I'm trying to do. Maybe...
8
9407
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 as CREATE TABLE SCEMANAME.LOG ( Sequence DECIMAL(9 ,0) NOT NULL ,
0
4057
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 following: 1) gets query string from url and filters records (works great) via a Details View 2) shows notes that have been added to the record shown in the details view using a grid view, and it filters the data by looking at the ID that is selected in...
5
3568
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, openingBalance): dec = decimal.Decimal(openingBalance)
0
8615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9033
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.