none
.rdlc and reportviewer RRS feed

  • Question

  • Can someone please assist me?  I am using .rdlc reports in studio, and I've got a frmReport.vb that contains a reportviewer.  I don't want to set only one report as the source.  Isn't there some way to programmatically set the source of the reportviewer depending on user criteria?

    Part 2 of this question.

    I'd also like to programmatically set the dataset and binding (if any) for this.

    My 2 reports (rptAdmit and rptTriage - both .rdlc) are each linked somehow to my dataset.  Fields on the Admit report are from OBAdmit and fields on the Triage report are from OBTriage, both belonging to FormsDataSet.

    I have 2 classes as well that use fill, update, delete queries.  One is OBAdmit.vb where i reference the OBAdmitTableAdapter and OBAdmitTable, and another is OBTriage where I reference OBTriageTableAdapter and OBTriageTable.  From both of these classes, I can perform various queries.  Some of them fill the FormsDataSet that contains the two table (Admit and Triage).

    How can I get my reportviewer to show the Admit Report when someone selects an Admit record, or a Triage Report when someone selects a Triage record, and have the OBAdmit or OBTriage (depending) fill the data set to populate the report.  I don't want the 3 objects to show up on the frmReport for reportviewer (FormsDataSet, OBAdmitBindingSource, OBAdmitTable) or for Triage either.

    Does anyone understand what I'm talking about?  HELP????

    Tuesday, July 25, 2006 6:21 PM

All replies

  • As per my understanding I guess you can do both of them

    I'm not a VB guy so I'll give the C# code for part-1

    Drag and drop a ObjectDataSource object (lets assume objectDataSource) on to the page. Now set the type name and select method.

    objectDataSource.TypeName = "CustomClass.Customtype";

    objectDataSource.SelectMethod =  "CustomMethod";

    ReportDataSource reportdatasource = new ReportDataSource();

    reportdatasource.Name = "ReportDataSetName"; //This should be the name of the DataSet in .rdlc file

    reportdatasource.DataSourceId = "objectDataSource";

    reportViewer.LocalReport.DataSources.Add(reportdatasource);

    reportViewer.LocalReport.ReportPath = ReportConfigurationHandler.GetReportPath("ReportPath"); //ReportPath should be path of the .rdlc file.

    You can change the above parameters according to the user selection.

    Part-2

    Please be more clear.

     

    Wednesday, July 26, 2006 6:34 PM
  • I can get the reportviewer to have different reports as it's source.  I figured that out.

    The problem is the binding.

    When I manually select a report.rdlc as the source for my reportviewer, I get the following code generated:

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

    'TODO: This line of code loads data into the 'FormsDataSet.OBAdmit' table. You can move, or remove it, as needed.

    Me.OBAdmitTableAdapter.Fill(Me.FormsDataSet.OBAdmit)

    Me.ReportViewer1.RefreshReport()

    End Sub

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

    This I understand.  Also, here's the code behind the scenes (not the full code, but just pertinent parts):

    Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource

    Me.ReportViewer1 = New Microsoft.Reporting.WinForms.ReportViewer

    Me.FormsDataSet = New OBIXAPP.FormsDataSet

    Me.OBAdmitBindingSource = New System.Windows.Forms.BindingSource(Me.components)

    Me.OBAdmitTableAdapter = New OBIXAPP.FormsDataSetTableAdapters.OBAdmitTableAdapter

    CType(Me.FormsDataSet, System.ComponentModel.ISupportInitialize).BeginInit()

    CType(Me.OBAdmitBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()

    Me.SuspendLayout()'

    'ReportViewer1

    'ReportDataSource1.Name = "FormsDataSet_OBAdmit"

    ReportDataSource1.Value = Me.OBAdmitBindingSource

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

    Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OBIXAPP.rptAdmit.rdlc"

    Me.ReportViewer1.Location = New System.Drawing.Point(12, 4)

    Me.ReportViewer1.Name = "ReportViewer1"

    Me.ReportViewer1.Size = New System.Drawing.Size(889, 546)

    Me.ReportViewer1.TabIndex = 0'

    'FormsDataSet'

    Me.FormsDataSet.DataSetName = "FormsDataSet"

    Me.FormsDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema

    ''OBAdmitBindingSource

    Me.OBAdmitBindingSource.DataMember = "OBAdmit"

    Me.OBAdmitBindingSource.DataSource = Me.FormsDataSet'

    'OBAdmitTableAdapter'

    Me.OBAdmitTableAdapter.ClearBeforeFill = True'

    CType(Me.FormsDataSet, System.ComponentModel.ISupportInitialize).EndInit()

    CType(Me.OBAdmitBindingSource, System.ComponentModel.ISupportInitialize).EndInit()

    Me.ResumeLayout(False)

    End Sub

    Friend WithEvents ReportViewer1 As Microsoft.Reporting.WinForms.ReportViewer

    Friend WithEvents OBAdmitBindingSource As System.Windows.Forms.BindingSource

    Friend WithEvents FormsDataSet As OBIXAPP.FormsDataSet

    Friend WithEvents OBAdmitTableAdapter As OBIXAPP.FormsDataSetTableAdapters.OBAdmitTableAdapter

    End Class

    With a little bit of conditional statments I can change the source of reportviewer to be either rptAdmit.rdlc, or rptTriage.rdlc, this is not a problem.  But the dataset doesn't seem to be the same as the dataset that I fill from my 2 classes (OBAdmit.vb and OBTriage.vb)

    I don't want all these bindingsources and stuff to show up on my frmReport (and the reportviewer control).   I just want the reportviewer to open up the report that I specify, AND I want the report to use the FormsDataSet that I have in my project.  When my class (OBTriage) performs a fill on that dataset, I want the report to be using that fill results.

    Wednesday, July 26, 2006 7:04 PM
  • The rptAdmit.rdlc file is using FormsDataSet_OBAdmit as it's datasource.

    Likewise rptTriage.rdlc is using FormsDataSet_OBTriage.

    But if I try to use my classes that fill the dataset, instead of the OBTriageBindingSource (whatever the hell this is), and the OBTriageTableAdapter, I get the error that I need to create an instance of FormsDataSet_OBTriage.  I don't get this.

    My class (OBTriage.vb) creates a Triage Table Adapter AND Triage Table.

    It then fills the Data Set via a function in the class:  LoadAll(), which is similar to the TableAdapter.Fill()

    I have forms that use this dataset when I fill it, but the report doesn't seem to want to use it.

    I know it's the ReportDataSource that I should be setting the value to something, but what?  Forms Data Set is what I need, and OBTriage is the correct table, but nothing's happening, except for the error.

    Wednesday, July 26, 2006 7:11 PM