0

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);
            }
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by BitBlt
0

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.

Edited by BitBlt: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.