How do i use linq as datasource for a Microsoft report

var exams = (from appointment in appointments select new {coursecode = (appointment.Tag as exam).ID}).ToList();

rpt.LocalReport.DataSources.Add(new ReportDataSource("dsExam". exams.AsEnumerable()));
rpt.ProcessingMode = ProcessingMode.Local;
rpt.RefreshReport();

Each appointment object contains an exam object. I would like to use the results of the linq query as the datasource of my report. However only the first row in IEnumerable exams is shown in the report even though it contains 81 rows. How can i fix this.

Answers


var exams = (from appointment in appointments
               select new
                    {
                          ((Exam)appointment.CustomFields["Field"]).Id,
                          ((Exam)appointment.CustomFields["Field"]).Name,
                          ((Exam)appointment.CustomFields["Field"]).Date,
                                     ((Exam)appointment.CustomFields["Field"]).Period.StartTime,
                                     ((Exam)appointment.CustomFields["Field"]).Period.EndTime,
                                     Location = ((Exam)appointment.CustomFields["Field"]).Location.Name
                                });

        SetDataSource(exams);


    private void SetDataSource(object exams)
    {          
        scheduleBindingSource.DataSource = exams;
        this.rpTTViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
        this.rpTTViewer.RefreshReport(); 
    }

You can use code as below for your purpose :

//Create a dataset typed
DataSet ds = new DataSet();

//Constructor a dataset from Dataset Model, dataset use for crystal report
DataSet1.print_salesDataTable tb = new DataSet1.print_salesDataTable();

//Queries with the conditions is ID
QLGiayDepEntities list = new QLGiayDepEntities();
var result = (from n in list.print_sales
              where n.OrderID == txtID.Text
              select n).ToList();

//Fill result to table
foreach (print_sales item in result)
{
    tb.Rows.Add(
        item.OrderID,
        item.DateOrder,
        item.NameEmployee,
        item.Total,
        item.Recieved,
        item.Discount,
        item.Sum,
        item.FromCustomer,
        item.Notes,
        item.Barcode,
        item.Name,
        item.ColorName,
        item.SizeID,
        item.Quantity,
        item.Price,
        item.SubTotal);
}

//checking to print
if (result == null)
{
    MessageBox.Show("null");
}
else
{
    ds.Tables.Add(tb);
    CrystalReportSales1.SetDataSource(ds);
    crystalReportViewer1.ReportSource = CrystalReportSales1;
    crystalReportViewer1.PrintReport();
}

Need Your Help

no audio in incoming call on dahdi channel

audio asterisk

I'm using Digium TE110p PCI card for PRI E1 line. I have done the configurations of dahdi. I can call out from the PRI using a softphone also I can call into PRI from an external phone or mobile. W...

Sencha Touch 2 list is invisible in container

list touch extjs containers

I'm trying to write simple view with list on container but i have some problems.