Click here to Skip to main content
13,835,880 members
Rate this:
Please Sign up or sign in to 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:

            DataSet dsa2 = new DataSet();
            DataTable dt2 = new DataTable();
            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);
            dataGridView1.DataSource = dt2;
            dataGridView1.Columns[0].Width = 286;
            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 180;
            dataGridView1.Columns[3].Width = 180;
Updated 3-Jul-17 1:43am
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The closing bracket is missing:
SELECT column2, ... From ( SELECT column2 As [column2], ... FROM Total  Where ... Group By column2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190114.1 | Last Updated 3 Jul 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100