Monday, March 12, 2012

Passing a report parameter to Reporting Services from VB

I have a Report that I want to access that has a parameter input for the date, Production_Date. I want to allow the user to use the DateTimePicker to select the date to use for Production_Date. I can't seem to find the correct way to format what I'm tring to do. My production date field is in a format without punctuation so that it becomes:

Dim ProductionDate = ((DateTimePicker1.Value.Month * 1000000) + (DateTimePicker1.Value.Day * 10000) + DateTimePicker1.Value.Year)

which gives me a value that I want to send as a parameter for the Reporting Services report that I have located on a tab in my project. The report is:

Me.ReportViewer1

I want to send the ProductionDate to the report where the report looks for Production_Date. Obviously, I 'm very new to this. I'd appreciate any suggestions. As it runs now, the default date is loaded (today's date) from the expression I calculated in Reporting services:

=(Now.Month*1000000)+(Now.Day*10000)+Now.Year

This is a big roadblock right now and I can't seem to put together a legal means to pass this value. Thanks for any help.

Have you tried passing DateTimePicker1.Value.ToString() to either Me.ReportViewer1.LocalReport.SetParameters() or Me.ReportViewer1.ServerReport.SetParameters() in a ReportParameter object?|||

Brian,

Thanks for the response. I'm not structuring the object correctly. I'm trying to understand how to set it up. I am enclosing where I'm at from copying some book examples, but I still have a way to go. In this case, I'm not really worrying about the calendar component just yet. I just want to understand how to pass this parameter to my report. In my case, the parameter is a date without delimiters for day or year. The parameter name is Production_Date. I'd like to allow my users to pass simple parameters such as the Production date or shift using the calendar component or a radio button for shift. In this report, there is only one parameter, the Production_Date. I would think this would be a common way to interact with Reporting Services because they use a third of the screen for their header. I'm still trying to get this figured out. Thanks again for the response.

Dim rp = New Microsoft.Reporting.WinForms.ReportParameter()

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

Me.ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://plant10plc/reportserver/")

Me.ReportViewer1.ServerReport.ReportPath = "/PLC Data Browser 2006/Report1"

Dim reportParameters = ReportViewer1.ServerReport.GetParameters()

rp.Name = "@.Production_Date"

rp.Value = 3292006

Me.ReportViewer1.ServerReport.SetParameters(reportParameters.rp)

Me.ReportViewer1.ShowParameterPrompts = False

Me.ReportViewer1.RefreshReport()

|||

The report viewer has a built in calendar prompt. If you set your parameter data type of date, it will show up in the built in parameter prompting. By using a datatype of date instead of string, you will need to use a formatted data (3/29/2006 instead of 3292006).

As far as your code, there are a few things to change:

1. You don't need to call GetParameters. The return value also doesn't have an rp property (that you are passing in to SetParameters)

2. Your parameter name shouldn't have the @.

3. You should pass in an array or ReportParameter objects to SetParameters. That array should have one element: rp.

|||

I spent time trying to modify my Date type from the calculated integer to the real datetime data type. In my system, I use a data collection service to collect information from the machines in a factory. I can't pass a string I create into a datetime field, but I can pass the timestamp() of the transaction. I kept my original value for keeping my records inserts and updates correct (my ProductionDate starts at 6:30am). What I found is that if I create a date, it enters a valus as 3/30/2006 12:00:00 am. If my software does it, it creates a date as 3/30/2006 3:45:00 pm, and updates to 3/30/2006 3:46:00 pm and so on. When I use the automatic date picker in Reporting Services, it only shows the fields that used M/D/YYYY 12:00:00 am. I could make it work, but there's no actual "date" datatype in SQL Server. This is really frustrating, but life continues....

In returning back to my original issue, I looked up the ReportParameter Members from the help files. It shows that there are Public Properties of ReportParameter which are Value and Name among others. Here's my code now:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim rp = New Microsoft.Reporting.WinForms.ReportParameter

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

Me.ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://plant10plc/reportserver/")

Me.ReportViewer1.ServerReport.ReportPath = "/PLC Data Browser 2006/Report1"

rp.Name = "ProductionDate"

rp.Value = 3292006

Me.ReportViewer1.ServerReport.SetParameters(rp)

Me.ReportViewer1.ShowParameterPrompts = False

Me.ReportViewer1.RefreshReport()

End Sub

End Class

When I run the code, it says "Public member 'Value' on type 'ReportParameter' not found." As I stated before, I'm kind of new to this. I appreciate the advice and would appreciate tips from Brian or anyone else that can explain what's probably a rookie mistake.

Thanks,

Jack

|||

The property name is called Values, not Value. And it is a collection, so you will need to write something like this:

rp.Values.Add(3292006)

Also, SetParameters takes an array of ReportParameters, not a single instance, so you will need to create an array of one element and assign rp to that first element.

No comments:

Post a Comment