Loading .rdlc report in Reportviewer manually in VB.Net
Asked Answered
U

1

5

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 …

enter image description here

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

enter image description here

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???

enter image description here

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

enter image description here

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

Urushiol answered 15/10, 2016 at 8:33 Comment(20)
Have you tried Dim rds = New ReportDataSource("DataSet1", data)Gilbye
Also data should be result of BonnyDataSet.AccMast_AllDetail.Gilbye
no, not happening, I tried this Dim data = BonnyDataSet.AccMast_AllDetail not working. Nothing working. It says Value type ReportDataSource cannot be converted to ReportDataSource... Now what's this ?? @RezaAghaeiUrushiol
What are namespaces which you Imported?Gilbye
It seems you have a compile time error not a run time.Gilbye
Imports Microsoft.Reporting.WebForms This is the only namespace I can see... Yes It's compile time error... @RezaAghaeiUrushiol
And that's the main problem! You should use Microsoft.Reporting.WinForms. Probably you are adding a wring dll too. You should have these references: Microsoft.Reporting.WinForms.dll and Microsoft.ReportViewer.Common.dll. Then Import Microsoft.Reporting.WinForms namespace.Gilbye
Okay, so wait, shall I add these references into the project from Project -> Add reference??? @RezaAghaeiUrushiol
After putting a ReportViewer on a Form, those references will be added automatically, but if you have a Microsoft.Reporting.WebForm.dll remove it, also replace Microsoft.Reporting.WebForms with Microsoft.Reporting.WinForms namespace.Gilbye
Okay I did Microsoft.Reporting.WinForms... And where to check this Microsoft.Reporting.WebForms.dll??? @RezaAghaeiUrushiol
Wait, I am checking all the code again and reply you @RezaAghaeiUrushiol
There is still errors... At Dim data = BonnydataSet.AccMast_AllDetail it shows error as reference to non shared member required an object reference. 1 more thing, My dataset is BonnyDataSet and DataTable in it is AccMast_AllDetail but still I cant select BonnyDataSet.AccMast_AllDetail.. After BonnyDataSet. the intellisense shows me AccMast_AllDetailDataTable`AccMast_AllDetailRow` etc..@RezaAghaeiUrushiol
When I select Dim data = BonnydataSet.AccMast_AllDetailDataTable it shows error BonnydataSet.AccMast_AllDetailDataTable` is a class type and cannot be used as an expression.@RezaAghaeiUrushiol
Surely it will throw exception, as I said data should be result of those data BonnyDataSet.AccMast_AllDetail, create an instance of data set and then call ds1.AccMast_AllDetail with parameters if it has any, it seem to be stored procedure. I can't test how it works, but get data using it and the use data. That's it.Gilbye
Its done, I took instance of the dataset and done... But 1 more problem I am facing, I am getting column names in report but not any datarows.... I checked my procedure and try to execute it in mssql server, I got data there.... Any Idea what am I missing??? @RezaAghaeiUrushiol
Check the result in application. How did you load data and how did you set it as Data source of report?Gilbye
And Make an answer to your last comment, I'll upvote that...@RezaAghaeiUrushiol
I checked the result, I get many records there in sql management studio... I am posting that as a new question and sending you the email of the question link, this question solved so let not discuss here, moreover this question has a long discussion...@RezaAghaeiUrushiol
Good job, I'll see you'r last question and I'll share idea if I had any :)Gilbye
Look into the answer and the way I loaded data. Maybe it solves the problem which you said in comments.Gilbye
G
5

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.

Gilbye answered 17/10, 2016 at 7:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.