mySQL exception in C# app, what's wrong with my syntax?

Posted on 2008-11-15
Last Modified: 2013-12-17
Hello -

I am trying to update a table with the code below and I keep getting the following exception:

"You have an error in your SQL syntax: check the manual that <SNIP>... for the right syntax to use near "Versed 5 mg/ml ' at line 1.

Notice the  " and ' surrounding the  medication.

If I change the syntax to

"where AnestheticMedNum = ' "

it still bombs

Any suggestions?


(NOTE: the code window edited out the plus signs so the "t's" denote plus signs

/// <summary>Updates the table anesthmedsinventory with the new quantity adjustment</summary>

		public static void updateMed_adj(string anesthMedName, double newQty, double qtyOnHand)


				double adjQty = newQty + qtyOnHand;

				string command = "UPDATE anesthmedsinventory set QtyOnHand = " t adjQty t  "where AnestheticMedNum = " t DataConnection.getMedNum(anesthMedName,adjQty);  



Open in new window

Question by:wjstarck
    LVL 13

    Accepted Solution

    I would suggest you to convert the doubles to string before adding it to the command

    string command = "UPDATE anesthmedsinventory set QtyOnHand = " + Convert.ToString(adjQty) +  "where AnestheticMedNum = " + Convert.ToString(DataConnection.getMedNum(anesthMedName,adjQty));  

    Now debug and copy the string stored in command. Run it in query analyzer or what ever tool to check if it runs fine.

    Author Closing Comment

    Looks like the getMedNum code is returning null which is creating the problem, because if I replace it with "1" everything works properly. Also I needed to put a space between the " and AnestheticMednum = " like so " AnestheticMedNum = "

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now