Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i run this query it's give an error "Join expression not supported."

My C# code with connection is :

C#
private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.jet.oledb.4.0; data source=" + Application.StartupPath + @"\DataInfo1.mdb;Persist Security Info=true;User Id='Admin'; password=;");
            con.Open();
            OleDbDataAdapter da = new OleDbDataAdapter("SELECT ct.custID, c.custName, c.custAdd,ct.custTranDate,ct.custTranType,ct.custPaidAmt,ct.custDueAmt, c.custArea FROM custTransaction ct left JOIN custDetails c ON ct.custID = c.custID and(ct.custTranDate BETWEEN #2/28/13# AND #3/1/13# and ct.custID='CUST-000002')", con);            
           DataSet ds = new DataSet();
           da.Fill(ds);
           CrystalReport1 cr = new CrystalReport1();
           cr.SetDataSource(ds);
            this.crystalReportViewer1.ReportSource = new CrystalReport1();
            this.crystalReportViewer1.Show();
        }


I'm using MSAccess in back end database..
how to fix it???

thanks in Advanced..
Posted

1 solution

ON ct.custID = c.custID and(ct.custTranDate BETWEEN
I see there is no space between and and bracket.

Try:
C#
OleDbDataAdapter da = new OleDbDataAdapter("SELECT ct.custID, c.custName, c.custAdd,ct.custTranDate,ct.custTranType,ct.custPaidAmt,ct.custDueAmt, c.custArea FROM custTransaction ct left JOIN custDetails c ON ct.custID = c.custID and (ct.custTranDate BETWEEN #2/28/13# AND #3/1/13# and ct.custID='CUST-000002')", con);   

Further, use parameterized query to pass values. That way you can pass the values of date and id as per defined easily without creating any syntax error.

Further, you should put the search criteria as WHERE clause, like:
C#
OleDbDataAdapter da = new OleDbDataAdapter("SELECT ct.custID, c.custName, c.custAdd,ct.custTranDate,ct.custTranType,ct.custPaidAmt,ct.custDueAmt, c.custArea FROM custTransaction ct left JOIN custDetails c ON ct.custID = c.custID WHERE ct.custID='CUST-000002' AND ct.custTranDate BETWEEN #2/28/13# AND #3/1/13#)", con);    
 
Share this answer
 
Comments
JayantaChatterjee 6-Mar-13 10:17am    
Sir, Thanks a Lottttt...

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