Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all, I've got an invoice program that I need to print an invoice from. I am using VB2012 RC and am having trouble doing this.

I have created 2 reports (rptList.rdlc and rptRecord.rdlc). List.rdlc is working fine - it gets all records from the db and displays as intended. Where I have a problem is with the currently selected record. I can't figure out how to get my textbox contents onto the rptRecord.rdlc report.

I am new to VB and the whole Programming world in general, so, any help would be greatly appreciated. The code I have thus far is as follows:

VB
#Region " PrintReport(SelectedRow) "
    ''' <summary>
    ''' Prints the currently selected record.
    ''' </summary>
    ''' <param name="SelectedRow"></param>
    ''' <remarks></remarks>
    Public Sub PrintReport(ByVal SelectedRow As String)

        Dim ds As New myDatabase_DataSet
        Dim dt As DataTable = ds.Tables(0)
        Dim dr As DataRow = dt.NewRow()

        dr("db_id") = CInt(SelectedRow)
        dr("owner_name") = frmMain.txtOwner.Text
        dr("owner_other") = frmMain.txtOther.Text
        dr("description") = frmMain.desc.Text
        dr("make") = frmMain.txtMake.Text
        dr("model") = frmMain.txtModel.Text
        dr("serialnumber") = frmMain.txtSerialNumber.Text
        dr("time_stamp") = frmMain.lblTimeStamp.Text

        dt.Rows.Add(dr)

        With frmPrintReports
            .Show()

            .ReportViewer2.LocalReport.ReportPath = _
               Application.StartupPath & "\rptRecord.rdlc"

            .ReportViewer2.LocalReport.DataSources.Clear()

            .ReportViewer2.LocalReport.DataSources.Add(New _
               ReportDataSource("myDatabase_DataSet1", ds.Tables(0)))

            .ReportViewer2.RefreshReport()

            .ReportViewer2.Visible = True
        End With

    End Sub
#End Region ' Prints the currently selected record.



I call the function with:

VB
PrintReport(lblCurrentRecord.Text)


Thanks,
Bill
Posted

1 solution

Your ReportViewer2.LocalReport has a method called SetParameters. Create a new List(Of ReportParameter), add your textbox contents with the name of the parameter in your report and send it in

Public Overrides Sub SetParameters(ByVal parameters As System.Collections.Generic.IEnumerable(Of Microsoft.Reporting.WinForms.ReportParameter))
     Member of Microsoft.Reporting.WinForms.LocalReport
Summary:
Sets report parameter properties for the local report.

Parameters:
parameters: An array of Microsoft.Reporting.WinForms.ReportParameter objects that contains a list of the report parameter properties.
 
Share this answer
 
v2
Comments
LCP2K 27-Jun-12 17:01pm    
Hi, thanks for your response. I know how to get my content into parameters but I am at a loss on how to begin coding this, and there seems to not be any info out there on how to achieve a solution to my predicament.

If you have any more sample code, I would appreciate it.

Thanks,
Bill
MarqW 28-Jun-12 2:39am    
I'm afraid I don't understand your question then. You asked how to get contents of a textbox into a report. You add a report parameter to be used in the rdlc file, then use SetParameters to set the parameter with the textbox's content. If that's not what you were after, please could you elaborate a bit more? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900