Solved

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

Posted on 2007-04-06
2
228 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 143

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

856 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