Click here to Skip to main content
15,887,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to produce reports using data from a access database. however, the reports bring out all the data in the table even if i use a where clause. here is my code.

C#
private void btnLoad_Click(object sender, EventArgs e)
        {
            dbc.openDbConn();
 
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT tblLoan.BannerID, tblStudent.Grade, tblStudent.StudName, "+
                                    "tblStudent.StudSurname, tblBook.Title, tblLoan.CopyID FROM tblStudent INNER JOIN "+
                                    "((tblBook INNER JOIN tblCopy ON tblBook.ISBN = tblCopy.ISBN) INNER JOIN tblLoan ON tblCopy.CopyID = tblLoan.CopyID) "+
                                    "ON tblStudent.BannerID = tblLoan.BannerID WHERE tblStudent.Grade = '" + cmbGrade.Text + "'", dbc.conn);
 
            DataSet dataset = new DataSet();
 
            dataAdapter.Fill(dataset, "tblLoan");
 
            DataTable table = dataset.Tables[0];
 
            if (dataset.Tables[0].Rows.Count == 0)
            {
                crystalReportViewer1.ReportSource = null;
 
                crystalReportViewer1.Refresh();
            }
            else
            {
                CrystalReport1 o<pre lang="c#">
bjRpt = new CrystalReport1();

objRpt.SetDataSource(table);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
}
}
Posted
Comments
ridoy 7-Aug-13 13:17pm    
the problem is in your query.
Maqhawe 7-Aug-13 13:19pm    
when i run this query in Access, it works perfect.
[no name] 7-Aug-13 13:26pm    
So? That just means that in Access when you run your query, you get the desired result. That does not mean that there is nothing wrong with your query in the code. What is "cmbGrade.Text"? That is probably your problem.
ridoy 7-Aug-13 13:28pm    
agree,a good point indeed.
Maqhawe 7-Aug-13 13:29pm    
cmbGrade.Text is a combo box. i also think it might be the problem here

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