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

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

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

1 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.
wjstarckAuthor Commented:
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 = "

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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