使用 linq 查询作为 microsoft 本地报告数据源 (WinForms)
如何使用 linq 查询作为本地报告(Microsoft Report)数据源(WinForms)? 我在 MyForm 中有一个 Microsoft 报表查看器控件,并且我有一个 linq 查询,如下所示:
var query = from colV in dal.v_TarafeGharardad join colT in dal.TBL_TarafeGharardad on colV.Id equals colT.PK_Id select colV;
我想使用 linq 查询作为 Microsoft 报表数据源。 我已经尝试过这个,但我真的知道这是错误的。
frmReportViewer ReportViewerForm = new frmReportViewer();
ReportViewerForm.rptViewer.LocalReport.DataSources.Add(new ReportDataSource("v_TarafeGharardad",query));
ReportViewerForm.rptViewer.LocalReport.ReportPath = Application.StartupPath + "rptTarafeGharardad.rdlc";
ReportViewerForm.Show();
解决方案是什么?(谢谢:-*)
更新:如果我可以将 linq 查询转换为 DataTable,问题就解决了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你正在做的事情看起来非常正确。我正是这样做的(这是 VB):
您需要检查的一点是您是否正确匹配报告中的数据源名称。您可以通过在文本编辑器中打开报告并查看数据源元素来检查这一点。
记忆中的另一件事,我大约一年没有使用过它,所以我可能是错的,我有一种微妙的感觉,你必须调用
rptViewer.Refresh()
或rptViewer.SetDisplayMode()
强制其渲染。请访问此网站,了解有关 ReportViewer 控件的大量信息:
http://www.gotreportviewer.com/
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/