Click here to Skip to main content
12,754,745 members (33,714 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
Hello, I have three tables and each table has a common attribute named "indate" and whenever i"m trying to join three tables using the following query it gives me an error "Syntax error in FROM clause". please solve my problem. Thanks.....
OleDbCommand cm = new OleDbCommand("SELECT payment.indate,payment.opening_balance,payment.purpose,payment.amount,income.indate,income.opening_balance,income.purpose,income.amount,bank_dep.indate,bank_dep.balance_opening,,bank_dep.amount FROM payment INNER JOIN income,bank_dep ON payment.indate=income.indate=bank_dep.indate",cn);

[Edit]Code block added[/Edit]
Posted 19-Feb-13 7:50am
Updated 19-Feb-13 7:56am
Member 11649391 30-May-15 2:03am
I have join 5 tables how to use inner join query for joining five tables in c# using ms access database?
this is my code
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\BS(CS)-6A\BS(CS)-6A\Database Managment System\Student Managment Project\School_Database\School_Managment_System.accdb;
Persist Security Info=False;";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
// string query = "select s.std_id, s.std_name, s.std_fname, s.std_phone, s.std_address, f.fee_paid, f.balance, f.fee_month, f.fee_year from std_info s join std_fees f on s.std_id = f.std_id";
string query = @"select *from (std_info inner join std_fees on std_info.std_id = std_fees.std_id), (inner join fees on fees.fee_id = std_fees.fee_id),(inner join class on class.class_id = fees.class_id)";
cmd.CommandText = query;

OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
dataGrid1.DataSource = dt;

catch (Exception ex) {
MessageBox.Show("Error" + ex);

1 solution

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

Solution 1

FROM payment INNER JOIN income,bank_dep

You can have more tables in FROM, like: FROM payment,income,bank_dep, but you can't have other than one single table after JOIN, and you have two. And you never can have an operation like a=b=c, but you have You need to split the statement across multiple joins:
SELECT payment.indate,payment.opening_balance,payment.purpose,payment.amount,income.indate,income.opening_balance,income.purpose,income.amount,bank_dep.indate,bank_dep.balance_opening,,bank_dep.amount 
FROM (payment 
INNER JOIN income ON payment.indate=income.indate)
INNER JOIN bank_dep ON income.indate=bank_dep.indate
Maciej Los 19-Feb-13 13:21pm
Chiklu.Soumya 19-Feb-13 13:40pm
it gives an error "syntax error(missing operator) in query expression 'payment.indate=income.indate INNER JOIN bank_dep on income.indate=bank_dep.indate"
Zoltán Zörgő 19-Feb-13 15:44pm
Sorry, Access is non-standard, it requires some parenthesis. See updated query.
Chiklu.Soumya 19-Feb-13 22:08pm
Thanks A lot. Now it's working fine.
Zoltán Zörgő 20-Feb-13 3:26am
You are welcome. Feel free to accept my answer.

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 | Mobile
Web02 | 2.8.170217.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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