none
Problem with array parameter in report RRS feed

  • Question

  • I have a form with a datagridview (CatalogDataGridView) in which one column of values is derived from another datagridview.  I have created a report to print the information contained in the CatalogDataGridView.  I am using the following code to capture the data from the one column into an array that I am then passing to a report parameter to use in the report:

    For i As Integer = 0 To List_Screen.CatalogDataGridView.Rows.Count - 1
      If List_Screen.CatalogDataGridView.Rows(i).Cells(9).Value Is DBNull.Value Then
         SerNum = " "
      Else
         SerNum = List_Screen.CatalogDataGridView.Rows(i).Cells(9).Value
      End If
      myAL.Add(SerNum)
    Next
    Dim params5(0) As ReportParameter
    params5(0) = New ReportParameter("SerNum", CType(myAL.ToArray(GetType(String)), String()))
    Me.ReportViewer1.LocalReport.SetParameters(params5)
    

    I know the code works because when I test it, it returns a separate value of the specified cell for each of the rows that are in the CatalogDataGridView.  The problem I am having is in the design of the report.  I have created a report parameter within the report designer (SerNum) and have used =Parameters!SerNum.Value as the Value of a textbox in the detail section of the report.  But when I run the report, it puts the first item of the array in each of the rows of the report.  For example, if I have 4 rows in the CatalogDataGridView and the value of the derived cell is 12/50 for row 1, 120/199 for row 2, 8/25 for row 3, and 2/10 for row 4, when I run the report 12/50 shows up for the 4 rows displayed in the report.  I have tried setting the report parameter to Multi-value, but I do not know what to put in the Available Values area.  If I leave the Available Values area blank I get #Error for each row.

    So how can I pass the report parameter to the report so that each row in the report will pull the corresponding index of the array?

    Hopefully I have explained what my problem is and what I want to accomplish.  But I'd be happy to give you any further information you might need.

    Thanks,
    John

    Saturday, January 29, 2011 4:35 AM

Answers

  • Pranil,

    After further investigation I found the solution to my problem.  What I needed to do is set the report parameter for SerNum to Multi-value, then for the TextBox Value I put the Expression as:

    =Parameters!SerNum.Value(RowNumber("DataDataSet_Catalog") -1)
    

    It now puts the different array values in each corresponding row of the report.

    Thank you for your time in trying to help me out.

    John

    • Marked as answer by reichard2 Monday, January 31, 2011 4:58 AM
    Monday, January 31, 2011 4:58 AM

All replies

  • Hi,

      For passing multiple values to report .Please declare a datatable and then add required columns to that table .  Then add the data to that table as you added in array above.    Then declare a report dataset and pass this table to the report dataset   and on report take one table and pass this dataset to that report.

    I am sure that this will help you for getting your solution.


    Thanks, Pranil Yambal | Pranil.Yambal@hotmail.com
    Saturday, January 29, 2011 11:50 AM
  • Pranil,

    If you are refering to the code below, I believe I am already doing what you suggest.  However, I may be missing a step that puts all the array data within the table or something else.

    Dim _filteredTable As DataTable
    _filteredTable = DirectCast(Me.CatalogBindingSource.Current, DataRowView).DataView.ToTable()
    Dim reportDataSource1 As New Microsoft.Reporting.WinForms.ReportDataSource()
    reportDataSource1.Value = _filteredTable
    Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataDataSet_Catalog", _filteredTable))
    Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
    

    If there is something that I am missing, suggested code would be great as I am still trying to learn VB.

    Thanks,
    John

    Saturday, January 29, 2011 3:22 PM
  • Hi John,

       I have try to run the report . and Please find the code for report as follows


    Dim
     _filteredTable As
     DataTable
    _filteredTable = DirectCast (Me .CatalogBindingSource.Current, DataRowView).DataView.ToTable()
    Dim reportDataSource1 As New Microsoft.Reporting.WinForms.ReportDataSource()
    reportDataSource1.Value = _filteredTable
    Me .ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.
    WinForms.ReportDataSource("DataSet_Catalog" , _filteredTable))
    Me .ReportViewer1.CLEAR()
    Me .ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)


    and use the dataset name in the report same as we mention above in the code i.e.DataSet_Catalog

    Thanks, Pranil Yambal | Pranil.Yambal@hotmail.com
    Saturday, January 29, 2011 5:24 PM
  • Pranil,

    I added the extra line of code - Me.ReportViewer1.Clear() that you suggested and the report still shows the first item of the array for each line of data in the report.  And I am using DataSet_Catalog as the dataset name in the report.  What else could I be doing wrong?  Did you test it and get the different values for the array to show up?

    Thanks,
    John

    Sunday, January 30, 2011 4:04 AM
  • Pranil,

    After further investigation I found the solution to my problem.  What I needed to do is set the report parameter for SerNum to Multi-value, then for the TextBox Value I put the Expression as:

    =Parameters!SerNum.Value(RowNumber("DataDataSet_Catalog") -1)
    

    It now puts the different array values in each corresponding row of the report.

    Thank you for your time in trying to help me out.

    John

    • Marked as answer by reichard2 Monday, January 31, 2011 4:58 AM
    Monday, January 31, 2011 4:58 AM