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开发者_JS百科.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.
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();
}
精彩评论