• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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

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
aatjan
Asked:
aatjan
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
dolemitehumantornadoCommented:
Hi,

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

query = "Update XYZ where myvariable = 0.75"

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now