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?

Thanks...

(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);  
				General.NonQ(command);
 
		}

Open in new window

wjstarckAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Toms EdisonTechnical ManagerCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 = "
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.