Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, Guys am working on c# and am facing an issue. "Additional information: Your query does not include the specified expression 'Item Name' as part of an aggregate function."
I don't know and I have tried many things but this error still there please help and tell me what is this and how can I resolve it
Thanks to Advance

What I have tried:

C#
"    con_string.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\Restaurant.accdb;Persist Security Info=False";
                            DataSet dsa = new DataSet();
                            DataTable dt = new DataTable();
                            dsa.Tables.Add(dt);
                            OleDbDataAdapter da = new OleDbDataAdapter();
                            da = new OleDbDataAdapter("SELECT sum(Column1) As [Item Price],[column2]As [Item Name],[column3]As [Table Name],[Flavours],[Customer Name],[Delivery Time],[Time] FROM Runtime Group by [column3]", con_string);
                            da.Fill(dt);
                            dataGridVaiew2.DataSource = dt;
                            con_string.Close();"
Posted
Updated 10-Nov-17 19:50pm
v2

You need to include the list of columns in the GROUP BY clause which are available in the SELECT list and doesn't associated with an aggregate function.
Your query should look like-
SQL
SELECT sum(Column1) As [Item Price],[column2]As [Item Name],[column3]As [Table Name],[Flavours],[Customer Name],[Delivery Time],[Time] FROM Runtime Group by [column3],[column2],[Flavours],[Customer Name],[Delivery Time],[Time]


But the result you will get probably is not what you expected. You need to include only those columns which are essentially needed.

Please let me know with a sample output in that case so that I can help further.

Thanks :)
 
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