Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Guys, i am facing an issue that is when i select my items from db so i get an error like this
Syntax error in FROM clause.


What I have tried:

con_string.Open();
            DataSet dsa2 = new DataSet();
            DataTable dt2 = new DataTable();
            dsa2.Tables.Add(dt2);
            OleDbDataAdapter da2 = new OleDbDataAdapter();
            da2 = new OleDbDataAdapter(string.Format("SELECT column2,Sum(MediumVal) As [Dine In], Sum(LargeVal) As [Deliery], Sum(RoyalVal) As [Take Away] From ( SELECT column2 As [column2], Switch(column3 like 'DineIn%', 1,True,0) As [MediumVal], Switch(column3 like 'Delivery%',1,True,0) As [LargeVal], Switch(column3 like 'TakeAway%', 1,True,0) As [RoyalVal] FROM Total  Where [Date] between #{0}# AND #{1}# AND [column2] = '"+dt1.ToString()+"' Group By column2", dateTimePicker1.Text, dateTimePicker2.Text), con_string);
            da2.Fill(dt2);
            dataGridView1.DataSource = dt2;
            con_string.Close();
            dataGridView1.Columns[0].Width = 286;
            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 180;
            dataGridView1.Columns[3].Width = 180;
Posted
Updated 3-Jul-17 0:43am
Comments
F-ES Sitecore 3-Jul-17 6:37am    
Use the debugger to see what the finished SQL is and look for syntax issues. I can't be bothered picking through it myself, but using the most casual of glances I see you have more "(" than ")" so it could just be you're missing a closing parenthesis.

1 solution

The closing bracket is missing:
SQL
SELECT column2, ... From ( SELECT column2 As [column2], ... FROM Total  Where ... Group By column2
 
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