【问题标题】:Overload resolution failed when trying to obtain data from access尝试从访问中获取数据时重载解析失败
【发布时间】:2016-08-20 15:26:48
【问题描述】:

我正在编写 POS 代码,但在尝试查看 access 数据库中的特定数据时遇到了问题。每次我尝试都会收到此错误:

错误 1 ​​重载解析失败,因为没有可访问的“新”最适合这些参数:

'Public Sub New(name As String, dataSourceValue As System.Collections.IEnumerable)':不是最具体的。

'Public Sub New(name As String, dataSourceValue As System.Data.DataTable)': 不是最具体的。

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

谁能告诉我我的代码有什么问题

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

错误在:

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

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    您可以将强类型 DataTable 转换为 DataTable 以解决此歧义问题:

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

    问题是在 2010 年有 two methods which are possible,一个是 DataTable,一个是 IEnumerable。强类型的DataTable 继承自TypedTableBase(Of T),后者继承自/实现:

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

    这就是为什么编译器不知道它应该使用哪个构造函数。他可以选择两个重载,所以你需要明确告诉编译器你想要什么。

    【讨论】:

    • 那么您可能想接受答案。不客气
    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 2021-06-13
    • 2015-09-14
    • 1970-01-01
    • 2012-11-07
    相关资源
    最近更新 更多