尝试从访问中获取数据时,重载决策失败

时间:2015-08-24 12:13:58

标签: vb.net

我正在编码POS,当我尝试查看访问数据库中的特定数据时,我陷入困境。每次我尝试都会收到此错误:

  

错误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)

1 个答案:

答案 0 :(得分: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继承自{implements>

TypedTableBase(Of T)
  • DataTable
  • IEnumerable(Of T)
  • IEnumerable

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