Hi. I am doing a C# windows form application and I am using Ms Access for the database. I have a sql query which retrieves data from 2 tables and I am displaying it in a crystal report. The problem I am having is for example i have 4 records which the query should return but it is returning 16! I think the query is not appropriate. Can anyone please guide me! Thnx

try
            {


                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Effort Tracker System\\Effort Tracker System\\ETSAccess.mdb");

                conn.Open();

               // string SQLString = "SELECT tblStaff_Daily_Task.Daily_Task, tblStaff_Daily_Task.Role_Description, tblTaskEfficiency.Total_Time, tblTaskEfficiency.TaskTimeEfficiency FROM tblStaff_Daily_Task, tblTaskEfficiency WHERE tblStaff_Daily_Task.Staff_Daily_Code = tblTaskEfficiency.Staff_Daily_Code AND Username ='" + comboBox1.Text + "'";
                string SQLString = "SELECT tblStaff_Daily_Task.Daily_Task, tblStaff_Daily_Task.Role_Description, tblTaskEfficiency.Total_Time, tblTaskEfficiency.TaskTimeEfficiency FROM tblStaff_Daily_Task INNER JOIN tblTaskEfficiency ON tblStaff_Daily_Task.Staff_Daily_Code = tblTaskEfficiency.Staff_Daily_Code AND Username ='" + comboBox1.Text + "'";

                OleDbDataAdapter da = new OleDbDataAdapter(SQLString, conn);
                DataSet ds = new DataSet();
                da.Fill(ds, "tblStaff_Daily_Task");
                conn.Close();

                CrystalReport5 objRpt = new CrystalReport5();
                objRpt.SetDataSource(ds.Tables[0]);
                crystalReportViewer1.ReportSource = objRpt;
                crystalReportViewer1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

It's hard to know for sure what the problem is without table layouts and query results. However, you might try to use

SELECT DISTINCT tblStaff_Daily_Task.Daily_Task, tblStaff_Daily_Task.Role_Description,...

If that doesn't work then post more details.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.