Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to run this query in c# winforms application,
NOTE: @ob is not a parameter it is a MySQL Variable which stores the value from first query and in turn serves the same value to second query,

the query is working fine on MySql Directly.
but when i run the same in my Program it throws an error
Fatal Error Encountered During Command Execution

string querystring = "SET @ob = (SELECT (Opening_Balance + Total_Income - Total_Expences) FROM transaction_master WHERE Date < '2014-10-09' ORDER BY Date DESC LIMIT 1); INSERT INTO `transaction_master`(`Date`, `Opening_Balance`, `Total_Income`, `Total_Expences`) VALUES ('2014-10-09',IFNULL(@ob,0),'1000','0');"

cmd.CommandText = querystring;
cmd.Connection = db;

Please Help me with this problem.
[no name] 9-Oct-14 9:05am    
delete all single quote and put it again then check. Hope so there is a problem single quote looks something different
vinay nasha 9-Oct-14 10:08am    
Did that Same Error
[no name] 9-Oct-14 10:28am    
You are missing somewhere. Please check carefully and u can solve that

Please use command Parameter and pass in query
Share this answer
vinay nasha 9-Oct-14 10:22am    
did that
but their is a problem
when you pass a command parameter it posts value between single quotes like 'Insert Into .....' which is throwing an sql error
You need to use the SQL Parameter Class[^] to set the value of @ob in to the cmd object.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900