How can I use a linq query as local report(Microsoft Report) data source (WinForms)?
I have a Microsoft Report Viewer Control in MyForm,And I have a linq query as this :
var query = from colV in dal.v_TarafeGharardad join colT in dal.TBL_TarafeGharardad on colV.Id equals colT.PK_Id select colV;
I want to use the linq query as Microsoft Report Data Source.
I have try this,but I really know it is wrong.
frmReportViewer ReportViewerForm = new frmReportViewer();
ReportViewerForm.rptViewer.LocalReport.DataSources.Add(new ReportDataSource("v_TarafeGharardad",query));
ReportViewerForm.rptViewer.LocalReport.ReportPath = Application.StartupPath + "rptTarafeGharardad.rdlc";
ReportViewerForm.Show();
What is the solution?(Thanks :-*)
Update: If I can convert the linq query to DataTable,the problem has been solved.
What you’re doing looks pretty much correct. I do exactly that (this is VB):
The one bit you need to check is that you are matching the datasource name that is in the report correctly. You can check this by opening the report in a text editor and looking in the datasources element.
The other thing from memory, and I’ve not used this in about a year so I might be wrong, I’ve got a niggling feeling you have to call either
rptViewer.Refresh()orrptViewer.SetDisplayMode()to force it to render.Take a look at this website for plenty of info on the ReportViewer control:
http://www.gotreportviewer.com/