5

I am new to C# and ASP .NET programming. I am making a crystal report in .net. I setup Dataset and DataTable. For report sources.

I am getting data from a linq query. and after that I am populating them in a instance of Dataset. I use debugger and it shows that I have data from the query. But my crystal reeport just shows the column heading not the column data.

Here is my code:

    private void ViewReport()
    {
        DataSet1 Dataset = new DataSet1();
        DataTable rptTable = Dataset.Tables["Emp_info"];
        DataTable rptTab = Dataset.Tables["Attendance_table"];
        Ind_attendance_rpt rptAtd = new Ind_attendance_rpt();
        DataRow dataRow1; // declaring Row of dataset
        DataRow dataRow2;
        //IndividualAttendance rptAtt = new IndividualAttendance();
        var rport = from att in db.Attendance_tables
                    join emp in db.Emp_infos on att.Login_id equals emp.ID 
                    orderby att.Id
                    select new
                    {
                        att.Id,
                        emp.Emp_name,
                        emp.ID,
                        emp.Designation,
                        emp.Dept,
                        att.Entry_time,
                        att.Exit_time,
                        att.Status,
                        att.Date
                    };
        Dataset.Tables["Emp_info"].Clear();
        Dataset.Tables["Attendance_table"].Clear();
        foreach (var rt in rport)
        {
            dataRow1 = rptTable.NewRow();
            dataRow2 = rptTab.NewRow();
            dataRow2["Id"] = rt.Id;
            dataRow1["Emp_name"] = rt.Emp_name;
            dataRow1["Designation"] = rt.Designation;
            dataRow1["Dept"] = rt.Dept;
            dataRow2["Entry_time"] = rt.Entry_time;
            dataRow2["Exit_time"] = rt.Exit_time;
            dataRow2["Status"] = rt.Status;
            dataRow2["Date"] = rt.Date;
            dataRow2["Login_id"] = rt.ID;
            Dataset.Tables["Emp_info"].Rows.Add(dataRow1);
            Dataset.Tables["Attendance_table"].Rows.Add(dataRow2);
        }
        rptAtd.SetDataSource(Dataset);
        CrystalReportViewer1.ReportSource = rptAtd;
    }

Can anyone tell me the reason?

Here is the result I am getting right now:

enter image description here

Debug Image:

enter image description here

1 Answer 1

1

Try to call Refresh on the report after setting the ReportSource

CrystalReportViewer1.Refresh();

you may have to use ToList() on your linq as well;

5
  • rptAtd is the crystal report. that has no TOList() method.
    – Rashad
    Commented May 1, 2014 at 6:40
  • Ignore my last message Commented May 1, 2014 at 6:45
  • You don't have to bind your report to a dataset. You already have the data in rport You can use it like rptAtd.SetDataSource(rport.ToList()); Commented May 1, 2014 at 6:52
  • do you see any value in rport when you are in debug mode? Commented May 1, 2014 at 7:08
  • Sorry, I can't think of anything else and I don't have Chrystal Reports installed on my machine to test it. Commented May 1, 2014 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.