I am designing a form to show the total cost on the listbox. I find that there is a error when I try to run this command
my purpose is show the courseID , numberOfStudent and the Total cost(the sum of column "operatingCost" and column"materialFee")
I want to search the TotalCost between two value.(the value of "price1" textbox and "price2" textbox) for example search all the totalCost between 700 and 1000
but after running the command there is an error shown on the message box
the error message is about ErrorSystem.Date.OleDB.OleDbExceptionError(0x80040E14) select query Operator sum(operatingCost + materialFee) >='700' andd <='1000' missing Operator
OleDbCommand cmd = new OleDbCommand("select courseId ,numOfStudent,sum( operatingCost + materialFee) AS Total_Cost from course group by courseId , numOfStudent having sum(operatingCost + materialFee) >= '" + price1.Text + "' and =<'" + price2.Text + "'", connection);
Where is my problem?Can somebody tell me please?
There is an error on your SQL. The correct use:
having sum(operatingCost + materialFee) between x and y
or
having sum(operatingCost + materialFee) >= x and sum(operatingCost + materialFee) <= y
Sources:
http://www.w3schools.com/sql/sql_and_or.asp
"... having sum(operatingCost + materialFee) between " + price1.Text + " and " + price2.Text, connection);
unquoted
Remember for every And condition, it's a new condition. therefore, you will need to define the column again with the your condition.
Example: SELECT * FROM [Products] WHERE Price >='2'and Price <='10'
you should use Total_Cost
instead of
sum(operatingCost + materialFee)
User contributions licensed under CC BY-SA 3.0