Loading .rdlc report in Reportviewer manually in V

2019-01-25 21:37发布

问题:

I need a serious help in reportviewer.
I seen a lot links, tried a lot codes every way but cannot find a proper solution. Please make me understand and clear my doubts even.
Totally confused which dataset to select during code and what is datasource.value thing which gives me error everytime...

I am showing the steps how I created the report and trying to make it work. This because I might have done any mistake in creating the reports and you people may catch it.

Now the problem is described below, I have many .rdlc reporting my project. What I done is

Note : Reportviewer containing form name is Reports.vb
RDLC reports are Reports1.rdlc,Report2.rdlc,...

1) Created Report like Add -> New Item -> Reporting -> Report -> Report1.rdlc
Report Name: Report1.rdlc

2) Then I add dataset from here like this …

3) DataSet properties opens, it even opens DataSource configuration Wizard. I select stored procedures because I want to fetch data from my stored procedures and pressed Finish.
Here DataSet Name is BonnyDataSet

4) After that, I select data source from dataset properties…
Now what is this Available datasets here in the last…???
And which dataset I have to consider during loading in ReportViewer???

5) Now I organised the column by adding the data columns from dataset1 shown below…

6) Now I added Reportviewer in form Reports.vb and tried a lot of codes….
Showing some of them here.

Private Sub Reports_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            'Select Case PubRepVar
            'Case "AccMast"
            Dim data As New BonnyDataSet
            Dim rds = New ReportDataSource("BonnyDataSet", data)
            ReportViewer.LocalReport.DataSources.Clear()
            ReportViewer.LocalReport.DataSources.Add(rds)   ‘------error here
            ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"
            ReportViewer.RefreshReport()
            'End Select

        Catch ex As Exception
            MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

I get the error as following:

BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'

I have no Idea on this error.

Another code I tried is ReportViewer.ProcessingMode = ProcessingMode.Local

        Dim localReport As LocalReport
        localReport = ReportViewer.LocalReport ‘-------error here

        localReport.ReportEmbeddedResource =
            "ReportViewerIntro.Report1.rdlc"

        Dim dataset As New DataSet("BonnyDataSet")

Here error shows like :

BC30311 : Value of type 'LocalReport' cannot be converted to 'LocalReport'.

And I tried many other but can’t understand what the problem is. Am I doing something wrong during the creation of .rdlc reports???

Needed help eagerly. Thanx

回答1:

You should consider these notes:

  1. You have a compoile-time error saying:

    BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'

    So you should check if you are using correct reference for ReportDataSource and using the class from correct namespace. A common problem is when you added Microsoft.Reporting.WebForms.dll as reference in a Windows Forms Project and added Import Microsoft.Reporting.WebForms namespace, so you will receive such exception.

  2. After fixing that, you should pay attention the name of DataSet in your report should be the same name which you use when creating a new ReportDataSource. For example if the name of DataSet is DataSet1, you should use such code:

    Dim rds = New ReportDataSource("DataSet1", data)
    
  3. The data which you want to pass to the report should be in the same structure which is used by report. For example, it should be an instance of a DataTable:

    TableAdapter1.Fill(Me.DataSet1, "Table1")
    Dim rds = New ReportDataSource("DataSet1", Me.DataSet1.Table1)
    
  4. When setting which report you are using, use correct resource name. For example if you have a Report1 in root of your project, and default namspace of your project is YourProjectNamespace then the resource name would be:

    ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"
    

    When your report is in a folder, the folder name also will be added to its resource name.