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

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
bonny
  • 688
  • 1
  • 14
  • 33
  • Have you tried `Dim rds = New ReportDataSource("DataSet1", data)` – Reza Aghaei Oct 15 '16 at 08:44
  • Also data should be result of `BonnyDataSet.AccMast_AllDetail`. – Reza Aghaei Oct 15 '16 at 08:50
  • 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 ?? @RezaAghaei – bonny Oct 15 '16 at 12:21
  • What are namespaces which you Imported? – Reza Aghaei Oct 15 '16 at 12:22
  • It seems you have a compile time error not a run time. – Reza Aghaei Oct 15 '16 at 12:23
  • `Imports Microsoft.Reporting.WebForms` This is the only namespace I can see... Yes It's compile time error... @RezaAghaei – bonny Oct 15 '16 at 12:40
  • 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. – Reza Aghaei Oct 15 '16 at 12:42
  • Okay, so wait, shall I add these references into the project from Project -> Add reference??? @RezaAghaei – bonny Oct 15 '16 at 13:10
  • 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. – Reza Aghaei Oct 15 '16 at 13:40
  • Okay I did `Microsoft.Reporting.WinForms`... And where to check this `Microsoft.Reporting.WebForms.dll`??? @RezaAghaei – bonny Oct 15 '16 at 14:00
  • Wait, I am checking all the code again and reply you @RezaAghaei – bonny Oct 15 '16 at 14:00
  • 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..@RezaAghaei – bonny Oct 15 '16 at 14:11
  • 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.@RezaAghaei – bonny Oct 15 '16 at 14:13
  • 2
    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. – Reza Aghaei Oct 15 '16 at 18:42
  • 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??? @RezaAghaei – bonny Oct 17 '16 at 07:03
  • Check the result in application. How did you load data and how did you set it as Data source of report? – Reza Aghaei Oct 17 '16 at 07:05
  • And Make an answer to your last comment, I'll upvote that...@RezaAghaei – bonny Oct 17 '16 at 07:05
  • 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...@RezaAghaei – bonny Oct 17 '16 at 07:10
  • Good job, I'll see you'r last question and I'll share idea if I had any :) – Reza Aghaei Oct 17 '16 at 07:12
  • Look into the answer and the way I loaded data. Maybe it solves the problem which you said in comments. – Reza Aghaei Oct 17 '16 at 07:22

1 Answers1

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.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398