How To Programmatically Generate Microsoft Report With Button Click Event

PRAISE PHS

Well-known member
Joined
Jun 2, 2011
Messages
58
Programming Experience
Beginner
Hi All,
Please can some one show me how to display report programmatically from sqlserver 2005 with microsoft report on microsoft report viewer in VS 2008 using vb.net. I want to put the code on a button click event.

PLS, NOTE...I AM NOT TALKING ABOUT CRYSTAL REPORT
Thanks in anticipation of your quick responses.
 
Here's some code I used in an old application to display a SSRS server report:
''' <summary>
''' Displays the output of a report.
''' </summary>
''' <param name="reportName">
''' The name of the report.
''' </param>
''' <param name="description">
''' The long description of the report.
''' </param>
''' <param name="path">
''' The path of the report file.
''' </param>
''' <param name="descriptionLabel">
''' The <b>Label</b> in which to display the report description.
''' </param>
''' <param name="viewer">
''' The <b>ReportViewer</b> in which to display the report output.
''' </param>
Private Sub DisplayReport(ByVal reportName As String, ByVal description As String, ByVal path As String, ByVal descriptionLabel As Label, ByVal viewer As ReportViewer)
	descriptionLabel.Text = description
	viewer.ServerReport.ReportServerUrl = New Uri(Program.Options.ReportingServicesWebServiceUrl)
	viewer.ServerReport.DisplayName = reportName
	viewer.ServerReport.ReportPath = path
	viewer.RefreshReport()
	viewer.Show()
End Sub
If you're using a client report, which I imagine you are, then it will along similar lines but not the same. You'll need to use the ClientReport property of the ReportViewer control so you should check it out and see what properties its type exposes and whether it makes sense for you to set them.
 
Last edited:
Here's some code I used in an old application to display a SSRS server report:
''' <summary>
''' Displays the output of a report.
''' </summary>
''' <param name="reportName">
''' The name of the report.
''' </param>
''' <param name="description">
''' The long description of the report.
''' </param>
''' <param name="path">
''' The path of the report file.
''' </param>
''' <param name="descriptionLabel">
''' The <b>Label</b> in which to display the report description.
''' </param>
''' <param name="viewer">
''' The <b>ReportViewer</b> in which to display the report output.
''' </param>
Private Sub DisplayReport(ByVal reportName As String, ByVal description As String, ByVal path As String, ByVal descriptionLabel As Label, ByVal viewer As ReportViewer)
    descriptionLabel.Text = description
    viewer.ServerReport.ReportServerUrl = New Uri(Program.Options.ReportingServicesWebServiceUrl)
    viewer.ServerReport.DisplayName = reportName
    viewer.ServerReport.ReportPath = path
    viewer.RefreshReport()
    viewer.Show()
End Sub
If you're using a client report, which I imagine you are, then it will along similar lines but not the same. You'll need to use the ClientReport property of the ReportViewer control so you should check it out and see what properties its type exposes and whether it makes sense for you to set them.

Thanks Jim for the reply.
 
Back
Top