Solved

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

Posted on 2007-04-06
2
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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