emilkitua emilkitua - 3 months ago 22
Vb.net Question

Overload resolution failed when trying to obtain data from access

I am coding a POS and I am stuck when I try to view specific data from the access database. Every time I try I get this error:


Error 1 Overload resolution failed because no accessible 'New' is most specific for these arguments:

'Public Sub New(name As String, dataSourceValue As System.Collections.IEnumerable)': Not most specific.

'Public Sub New(name As String, dataSourceValue As System.Data.DataTable)': Not most specific.

C:\Users\EMIL\Documents\Visual Studio 2010\Projects\P.O.S\FrmMain.vb 402 17 AdvanceLoginForm


Please can anyone show me whats wrong with my code

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If ComboBox1.Text = "Total Profit for all time" Then
Dim TA As New POSDSTableAdapters.TotalProfitForAllTimeTableAdapter
Dim TmpDS As New POSDS
TA.Fill(TmpDS.TotalProfitForAllTime)

'clear previous datasource
RV.LocalReport.DataSources.Clear()

'create new datasource
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("POSDS_TotalProfitForAllTime.rdlc", TmpDS.TotalProfitForAllTime)

RV.LocalReport.DataSources.Add(RDS)
RV.LocalReport.ReportEmbeddedResource = "POS.TotalProfitForAllTime.rdlc"
RV.RefreshReport()
ElseIf ComboBox1.Text = "Total Profit between two dates" Then
Dim TA As New POSDSTableAdapters.TotalProfitForAllTimeTableAdapter
Dim TmpDS As New POSDS

TA.FillByFilteringBetweenTwoDates(TmpDS.TotalProfitForAllTime, DateTimePicker1.Value, DateTimePicker2.Value)

'clear previous datasource
RV.LocalReport.DataSources.Clear()

'create new datasource
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("POSDS_TotalProfitForAllTime.rdlc", TmpDS.TotalProfitForAllTime)

RV.LocalReport.DataSources.Add(RDS)
RV.LocalReport.ReportEmbeddedResource = "POS.TotalProfitBetweenTwoDates.rdlc"
RV.RefreshReport()
End If
End sub


The error is at:

Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("POSDS_TotalProfitForAllTime.rdlc", TmpDS.TotalProfitForAllTime)

Answer

You can cast the strongly typed DataTable to DataTable to resolve this ambiguity issue:

Dim table As DataTable = DirectCast(TmpDS.TotalProfitForAllTime, DataTable)
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("POSDS_TotalProfitForAllTime.rdlc", table)

The problem is that in 2010 there are two methods which are possible, one that takes a DataTable and one that takes an IEnumerable. A strongly typed DataTable inherits from TypedTableBase(Of T) which inherits from/implements:

  • DataTable,
  • IEnumerable(Of T),
  • IEnumerable

That's why the compiler doesn't know which contsructor it should use. He could choose both overloads, so you need to tell the compiler explicitly what you want.

Comments