Solved

handle a double variable constructed in vb.net in an sql query

Posted on 2007-04-06
2
219 Views
Last Modified: 2013-11-26
Hi all,

I'm strugling with the following issue:-

want to construct an sql query within a vb.net program.
this query contains a variable which is a double like
Dim MyDouble as Double = 0.75
so the query should become like:-
Dim query as string

query = "Update XYZ where myvariable = '0.75'"

How to construct this and how to prevent that it becomes like

Query =  "Update XYZ where myvariable = '0,75'"    (see the comma in stead of the point)

This is necessary because i want to run
Dim SpToRun As New Data.SqlClient.SqlCommand
            SpToRun.CommandType = CommandType.Text
            SpToRun.CommandText = Query
            SpToRun.Connection = loConnection

and in one way or another the engine  sees the 0,75 as a varchar ...
0
Comment
Question by:aatjan
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18865835
use the parameters

Query =  "Update XYZ where myvariable =  @value  "    

Dim SpToRun As New Data.SqlClient.SqlCommand
SpToRun.CommandType = CommandType.Text
SpToRun.CommandText = Query
SpToRun.Connection = loConnection
SpToRun.Parameters.Add("@value", 0.75)

SpToRun.ExecuteNonQuery
0
 
LVL 1

Accepted Solution

by:
dolemitehumantornado earned 500 total points
ID: 18866016
Hi,

Remove the ' ' from around your 0.75.  That identifies it as a varchar.

query = "Update XYZ where myvariable = 0.75"

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now