VB.net 2005 Reportviewer help

S

steve

Hi All

I need help on how to manipulate the data returned from the database for
displaying in the new reportviewer at runtime

So far I have an rdlc file with a dataset, binding source and Tableadapter
as created by the wizard and all work fine

However I want to be able to change the displayed report at runtime when the
user selects a different report type from a combobox but am unsure how to do
this

dim sql as string = "select * from members order by surname"

dim dt as datatable = getdata(sql)

Me.MembersTableAdapter.Fill(dt)

Me.ReportViewer1.RefreshReport()

This doesn't work



Regards
Steve
 
S

Steven Cheng[MSFT]

Hello Steve,

Welcome to the MSDN newsgroup.

From your description, I understand you're using the .NET 2.0's winform
ReportViewer control to display some client report(based on rdlc file) in
your winform application. However, since you have mulitple such rdlc
template and various datasources, you're wondering how dynamically change
the reportViewer's datasource(displayed data) and refresh it, correct? If
anything I've missed, please feel free to let me know.

Based on my research, the winform reportviewer control does support
programmatic datasource configuration(both server report or local report)
through its certain properties. And to dynamically update the report data,
you can:

1. For server report, you can simply change the "ServerReport" property's
certain sub properties and refresh the reportviewre. e.g.

=============
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click

Me.ReportViewer1.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Remote

Me.ReportViewer1.ServerReport.ReportServerUrl = New
Uri("http://localhost/ReportServer/")
Me.ReportViewer1.ServerReport.ReportPath =
"/ReportProj1/GroupReport"
Me.ReportViewer1.RefreshReport()

End Sub
===============

2. As for LocalReport, which rely on a rdlc template (on file system or
embeded in assembly resource), it is more complex to rebind the datasource
comparing to ServerReport model. Actually, we need to reset the
reportViewer first, and then add the new datasoruce (ReportDataSource)
needed, and change the LocalReport's reportPath(or embededResource name).
After that, still refresh the ReportViewer control to see the update. e.g.

=========================
==========================
Private Sub btnClientTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClientTest.Click

Me.ReportViewer1.Reset()
Me.ReportViewer1.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local


Dim newds As New
Microsoft.Reporting.WinForms.ReportDataSource("NorthwindDataSet1_Region")
newds.Value = Me.RegionBindingSource

Me.ReportViewer1.LocalReport.DataSources.Add(newds)


Me.ReportViewer1.LocalReport.ReportEmbeddedResource =
"ClientReportApp.Report2.rdlc"
Me.ReportViewer1.RefreshReport()

End Sub
========================

In the above example, the "RegionBindingSource" is a pregenerated winform
BindingSource(configured throug DataSet/DataAdapter pairt) in design-time.


Hope this helps. If there is any other problems you met, please feel free
to post here.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top