Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal report not showing any data

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

like image 362
Rashad Avatar asked Nov 11 '22 08:11

Rashad


1 Answers

Try to call Refresh on the report after setting the ReportSource

CrystalReportViewer1.Refresh();

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

like image 184
user3373870 Avatar answered Nov 14 '22 22:11

user3373870