locked
VB.NET - RDLC - The report data source object must be of the type... RRS feed

  • Question

  • User-1134314964 posted

    Hello..

    I have a main report and a sub report.  The subreport is populated with a variable from the main report.

    I've been working on getting the sub report to populate properly and thought I had it.  But during debugging, I get the above error.  This is occurring on the e.DataSources.Add line.

    Any ideas on how to resolve this issue?  Thanks..

    An exception of type 'System.ArgumentException' occurred in Microsoft.ReportViewer.WebForms.dll but was not handled in user code
    Additional information: The report data source object must be of the type System.Data.DataTable, System.Collections.IEnumerable, or System.Web.UI.IDataSource.

    Public Sub MySubreportEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    	Dim tasub As OTBTableAdapters.vw_OTB_SPATableAdapter = New OTBTableAdapters.vw_OTB_SPATableAdapter
    	Dim dtsub As OTB.vw_OTB_SPADataTable = New OTB.vw_OTB_SPADataTable
    	Dim SpecialAssessmentsVariable As Integer = e.Parameters(0).Values(0)
    	tasub.FillBySpecialAssessments(dtsub, SpecialAssessmentsVariable)
    
    	e.DataSources.Add(New ReportDataSource("SpecialAssessments", tasub))
    
    End Sub

    Monday, April 25, 2016 8:12 PM

Answers

  • User-1134314964 posted

    Holy ****!  I finally got something which is working.

    Public Sub MySubreportEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    	Dim tasub As OTBTableAdapters.vw_OTB_SPATableAdapter = New OTBTableAdapters.vw_OTB_SPATableAdapter
    	Dim dtsub As OTB.vw_OTB_SPADataTable = New OTB.vw_OTB_SPADataTable
    
    	Dim SpecialAssessmentsVariable As String = e.Parameters(0).Values(0)
    
    	tasub.FillBySpecialAssessments(dtsub, SpecialAssessmentsVariable)
    
    	Dim rdssub As ReportDataSource = New ReportDataSource
    	rdssub.Name = "SpecialAssessments"
    	rdssub.Value = dtsub
    
    	e.DataSources.Add(rdssub)
    End Sub

    Weibo Zhang, thank you for all your assistance in this matter.  In all the postings I've made to all the different forums, you were the only one which took time to assist me in my issue.  Thank you again..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 10, 2016 2:03 PM

All replies

  • User-219423983 posted

    Hi spook_man,

    spook_man

    The report data source object must be of the type System.Data.DataTable, System.Collections.IEnumerable, or System.Web.UI.IDataSource

    According to below article you could know that the value of “ReportDataSource” should be an instance of DataTable, a IEnumerable value (for example, DataView or Array), or a BindingSource.

    https://msdn.microsoft.com/en-us/library/ms251736.aspx#Anchor_1

    In your above code, you pass a “OTBTableAdapters.vw_OTB_SPATableAdapter” as the value, so you should make sure whether the class “OTBTableAdapters.vw_OTB_SPATableAdapter” meets with the above value restriction. Maybe you’d better use DbDataAdapter.Fill Method (DataTable) to get a table result and the pass it to the datasoure.

    The following is a demo and you could have a look.

    https://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.subreportprocessing.aspx?f=255&mspperror=-2147217396&cs-save-lang=1&cs-lang=vb#code-snippet-2

    Best Regards,

    Weibo Zhang

    Tuesday, April 26, 2016 5:50 AM
  • User-1134314964 posted

    I'm not sure what I'm missing.  My code looks like the code in the examples shown.  But I keep getting the same errors.

    I've tried separate datasets as well as combined datasets (with TableAdapters), but still the same issue.  I've tried adding a DataTable within the DataSet, but the code doesn't see this an an option when entering code.

    I am getting the proper value from the e.Parameters(0).Values(0) option, so that aspect appears to be working properly.

    Thanks..

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    	If Not IsPostBack Then
    		Dim myFirstreportpath As String = Server.MapPath("/reports/FirstHalf_NewLayout_Parcel.rdlc")
    
    		Dim ta As OTBTableAdapters.vw_OTB_2015NewLayoutTableAdapter = New OTBTableAdapters.vw_OTB_2015NewLayoutTableAdapter
    		Dim dt As OTB.vw_OTB_2015NewLayoutDataTable = New OTB.vw_OTB_2015NewLayoutDataTable
    		ta.FillMainReport(dt, userparcel, taxyearentry)
    		Dim rds As ReportDataSource = New ReportDataSource
    		rds.Name = "Dataset1"
    		rds.Value = dt
    
    		Dim parcel As ReportParameter = New ReportParameter("parcel", userparcel.ToString)
    		Dim TaxYear As ReportParameter = New ReportParameter("TaxYear", taxyearentry.ToString)
    
    		ReportViewer1.LocalReport.DataSources.Clear()
    		ReportViewer1.LocalReport.ReportPath = myFirstreportpath
    		ReportViewer1.LocalReport.SetParameters(New ReportParameter() {TaxYear, parcel})
    		ReportViewer1.LocalReport.DataSources.Add(rds)
    
    		AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf MySubreportEventHandler
    
    		ReportViewer1.LocalReport.Refresh()
    	End If
    End Sub
    
    Public Sub MySubreportEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    	Dim tasub As OTBTableAdapters.vw_OTB_SPATableAdapter = New OTBTableAdapters.vw_OTB_SPATableAdapter
    	Dim dtsub As OTB.vw_OTB_SPADataTable = New OTB.vw_OTB_SPADataTable
    	Dim SpecialAssessmentsVariable As Integer = e.Parameters(0).Values(0)
    
    	tasub.FillBySpecialAssessments(dtsub, SpecialAssessmentsVariable)
    
    	'Getting following error/stopage on line below
    	'An Exception of type 'System.ArgumentException' occurred in Microsoft.ReportViewer.WebForms.dll but was not handled in user code
    	'Additional Information: The Report data source Object must be Of the type System.Data.DataTable, System.Collections.IEnumerable, Or System.Web.UI.IDataSource.
    
    	e.DataSources.Add(New ReportDataSource("SpecialAssessments", tasub))
    End Sub

    Friday, April 29, 2016 6:50 PM
  • User-219423983 posted

    Hi spook_man,

    As I said above, the value of “New ReportDataSource()” should be an instance of DataTable, a IEnumerable value, or a BindingSource.  It’s pointing to the second parameter of the “New ReportDataSource() method” in the problematic line.

    So, maybe you could change

    e.DataSources.Add(New ReportDataSource("SpecialAssessments", tasub))

    to

    e.DataSources.Add(New ReportDataSource("SpecialAssessments", dtsub))

    in your code to solve this error.<!--?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" /--><o:p></o:p>

    Best Regards, <o:p></o:p>

    Albert Zhang<o:p></o:p>

    Tuesday, May 3, 2016 8:20 AM
  • User-1134314964 posted

    Hello..

    Thank you for the reply.  I changed the code as you suggested, but no am getting the following error:

    Error	BC30521	Overload resolution failed because no accessible 'New' is most specific for these arguments:
        'Public Overloads Sub New(name As String, dataSourceValue As Object)': Not most specific.
        'Public Overloads Sub New(name As String, dataSourceValue As DataTable)': Not most specific.
        'Public Overloads Sub New(name As String, dataSourceValue As IEnumerable)': Not most specific.

    Thanks..

    Tuesday, May 3, 2016 2:20 PM
  • User-219423983 posted

    Hi spook_man,

    What type the “dtsub” is?  What type the “OTB.vw_OTB_2015NewLayoutDataTable” is? Is it a datatable type, a IEnumerable value (for example, DataView or Array), a BindingSource or others? Could you share the definition of “OTB.vw_OTB_2015NewLayoutDataTable”?

    Best Regards,

    Weibo Zhang

    Wednesday, May 4, 2016 6:48 AM
  • User-1134314964 posted

    Hello..

    I have DataSets with DataTables to feed information to the RDLC's.  I used these DataSets when creating the RDLC's.

    The DataTables are SQL queries to two different views.

    I've tried creating DataSets for just the sub-report and also added a subreport DataTable to the DataSet for the main report thinking if they're part of the same DataSet this would work. But it doesn't seem nothing is working properly.

    I'm at a lost.

    Thanks..

    Wednesday, May 4, 2016 6:02 PM
  • User-219423983 posted

    Hi spook_man,<!--?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" /--><o:p></o:p>

    I know what you want to achieve. Your above issue is more related to the data type of “tasub” and “dtsub”. You could try define the “dtsub” as DataTable and try again.<o:p></o:p>

    Besides, the following two links provide two demos about creating sub RDLC report and you could have a look and pay more attention to the data of “e.DataSources.Add(New ReportDataSource()”.<o:p></o:p>

    http://forums.asp.net/post/3464322.aspx<o:p></o:p>

    https://blogs.msdn.microsoft.com/selvar/2009/08/30/working-with-rdlc-and-passing-parameter-to-subreport-in-report-viewer-control/<o:p></o:p>

    Best Regards, <o:p></o:p>

    Weibo Zhang<o:p></o:p>

    Thursday, May 5, 2016 9:32 AM
  • User-1134314964 posted

    Yea, nothing is working.  I haven't a clue.

    The DataSet is configured with a TableAdapater for the query for the main and sub reports, to gather information.  The variable is being grabbed from the main report and it shows up in stepping through the code-behind.  The code behind is selecting the proper TableAdapater, so the DataTable shouldn't need to be defined since it's already defined in the DataSet.

    I'm at a loss and it shouldn't be this hard.  Why MS requires you to have code behind to feed a variable to a sub-report, I don't understand.  Crystal doesn't require this and it passes variables from the main report to the sub without any problems.

    Friday, May 6, 2016 3:28 PM
  • User-219423983 posted

    Hi spook_man,

    The DataSet is configured with a TableAdapater for the query for the main and sub reports, to gather information.  The variable is being grabbed from the main report and it shows up in stepping through the code-behind.  The code behind is selecting the proper TableAdapater, so the DataTable shouldn't need to be defined since it's already defined in the DataSet.

    About why I ask you define the “dtsub” as DataTable is because I’m not sure whether the “OTB.vw_OTB_2015NewLayoutDataTable” Inherits from VB.NET predefined type “DataTable”. If not, you should convert the “dtsub” to DatTable, not the “OTB.vw_OTB_2015NewLayoutDataTable”.

    Here, you should know that the class ““OTB.vw_OTB_2015NewLayoutDataTable” not must be the DataTable or a child class, it seems like a custom class that simply contains the name "DataTable". You could have a try now and it just a test. After that, please let me know the result.

    Besides, please show me the definition of the “OTB.vw_OTB_2015NewLayoutDataTable”. Otherwise, it’s not easy to help you find out the issue point and I just could give you my guess.

    Best Regards,

    Albert Zhang

    Saturday, May 7, 2016 7:29 AM
  • User-1134314964 posted

    Hello..

    OTB is a dataset; a .xsd file.

    Within this file, I have two TableAdapters configured; vw_OTB_2015NewLayout and vw_OTB_SPA.

    The vw_OTB_2015NewLayout table adapters has a vw_OTB_2015NewLayoutTableAdapter with a simple SQL select statement and two WHERE variables. The fill datatable is named FillMainReport and the return datatable is named GetDataMainReport.

    The vw_OTB_SPA table adapters has a vw_OTB_SPATableAdapter with a simple SQL select statement and one WHERE variables. The fill datatable is named FillBySpecialAssessments and the return datatable is named GetDataSpecialAssessments.

    The code should be calling these TableAdapters within this DataSet; and I assume it is.

    How to convert dtsub into a DataTable, I don't know.

    Within the OTB.xsd file, I added a DataTable named vw_OTB2_SPATableAdapter and added three columns which are to be used. I then changed the code to:

    Dim dtsub As OnlineTaxBills.vw_OTB2_SPATableAdapterDataTable = New OnlineTaxBills.vw_OTB2_SPATableAdapterDataTable


    But now, the:

    tasub.FillBySpecialAssessments(dtsub, SpecialAssessmentsVariable)

    line is reporting: Error: BC30311 Value of type 'OnlineTaxBills.vw_OTB2_SPATableAdapterDataTable' cannot be converted to 'OnlineTaxBills.vw_OnlineTaxbills_SPADataTable'.

    Again, I haven't a clue as to what is occurring. It shouldn't be this hard.

    Monday, May 9, 2016 2:52 PM
  • User-1134314964 posted

    Found a video on YouTube and followed what they did, and now, get a totally different error.

    e.DataSources.Add(New ReportDataSource("SpecialAssessments", OTB.vw_OTB_SPADataTable))

    Error states:

    BC30109	'OTB.vw_OTB_SPADataTable' is a class type and cannot be used as an expression.

    Monday, May 9, 2016 5:28 PM
  • User-1134314964 posted

    Even tried the same type of configuration as that of my main report, getting the "DataTable" type error again with this..........

    Public Sub MySubreportEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    	Dim tasub As OnlineTaxBillsTableAdapters.vw_OnlineTaxbills_SPATableAdapter = New OnlineTaxBillsTableAdapters.vw_OnlineTaxbills_SPATableAdapter
    	Dim dtsub As OnlineTaxBills.vw_OnlineTaxbills_SPADataTable = New OnlineTaxBills.vw_OnlineTaxbills_SPADataTable
    
    	Dim SpecialAssessmentsVariable As Integer = e.Parameters(0).Values(0)
    
    	tasub.FillBySpecialAssessments(dtsub, SpecialAssessmentsVariable)
    
    	Dim rdssub As ReportDataSource = New ReportDataSource
    	rdssub.Name = "SpecialAssessments"
    	rdssub.Value = tasub
    
    	e.DataSources.Add(rdssub)
    End Sub



    Monday, May 9, 2016 7:40 PM
  • User-219423983 posted

    Hi spook_man,

    For now, you could go back to the “e.DataSources.Add(New ReportDataSource("SpecialAssessments", dtsub))”.

    Then, you meet with an error “BC30521 Overload resolution failed because no accessible 'New' is most specific for these arguments”. About this error message, I think you’d better make clear which line causes this error. As usual, this error means you declare a variable with a class which doesn’t have corresponding Constructor.

    For example, you define a class “MyClass” which doesn’t has “Publich Sub New()” in it, when you use “Dim myClass as MyClass = new MyClass” would happen the above error.

    Best Regards,

    Weibo Zhang

    Tuesday, May 10, 2016 3:11 AM
  • User-1134314964 posted

    Well, here's the issue.  What's the difference between:

    e.DataSources.Add(New ReportDataSource("SpecialAssessments", tasub))

    and

    e.DataSources.Add(New ReportDataSource("SpecialAssessments", dtsub))

    The top one is using a tableadapter as a new datasource and the other is using a datatable as a datasource; within the same DataSet.

    But according to VSC2015, there's issues between the two.  The first being "The Report data source Object must be Of the type System.Data.DataTable, System.Collections.IEnumerable, Or System.Web.UI.IDataSource" and the later being "Overload resolution failed because no accessible 'New' is most specific for these arguments".  The later, I'm trying to make a system call to a new ReportDataSource; I'm not calling a special class or classname so why the error?  New ReportDataSource is system call.

    Personally, I think there's a major bug with VSC2015 which is causing this.  All the videos and all the code examples I've see, it's simply putting this or that and it works for them.  With me, I get an error with every different configuration I try.

    Heck, even trying a direct call to the DataTable (which an online video showed "works") 

    e.DataSources.Add(New ReportDataSource("SpecialAssessments", OTB.vw_OTB_SPADataTable))

    is giving me an error of "is a class type and cannot be used as an expression". 

    And another video shows the main report passing the appropriate variable to the subreport with it populating the subreport without any code-behind needed.

    I'm at a loss.  I've tried everything I can and nothing is working.

    Tuesday, May 10, 2016 1:26 PM
  • User-1134314964 posted

    Holy ****!  I finally got something which is working.

    Public Sub MySubreportEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    	Dim tasub As OTBTableAdapters.vw_OTB_SPATableAdapter = New OTBTableAdapters.vw_OTB_SPATableAdapter
    	Dim dtsub As OTB.vw_OTB_SPADataTable = New OTB.vw_OTB_SPADataTable
    
    	Dim SpecialAssessmentsVariable As String = e.Parameters(0).Values(0)
    
    	tasub.FillBySpecialAssessments(dtsub, SpecialAssessmentsVariable)
    
    	Dim rdssub As ReportDataSource = New ReportDataSource
    	rdssub.Name = "SpecialAssessments"
    	rdssub.Value = dtsub
    
    	e.DataSources.Add(rdssub)
    End Sub

    Weibo Zhang, thank you for all your assistance in this matter.  In all the postings I've made to all the different forums, you were the only one which took time to assist me in my issue.  Thank you again..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 10, 2016 2:03 PM