Vb.net 重载解析失败,因为没有可访问的“new”最适合这些参数
代码如下:Vb.net 重载解析失败,因为没有可访问的“new”最适合这些参数,vb.net,Vb.net,代码如下: If ComboBox1.Text = "Total profil for all time" Then Dim TA As New CPDBTableAdapters.TotalProfilForAllTimeTableAdapter Dim TmpDS As New CPDB TA.Fill(TmpDS.TotalProfilForAllTime) 'obriši prošli DS RV.Lo
If ComboBox1.Text = "Total profil for all time" Then
Dim TA As New CPDBTableAdapters.TotalProfilForAllTimeTableAdapter
Dim TmpDS As New CPDB
TA.Fill(TmpDS.TotalProfilForAllTime)
'obriši prošli DS
RV.LocalReport.DataSources.Clear()
'dodaj novi DS
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("", TmpDS.TotalProfilForAllTime)
RV.LocalReport.DataSources.Add(RDS)
RV.LocalReport.ReportEmbeddedResource = "change_password.report1.rdlc"
RV.RefreshReport()
End If
问题在于:
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("",
TmpDS.TotalProfilForAllTime)
错误消息:
重载解析失败,因为没有可访问的“new”最适合这些参数。根据TmpDS.TotalProfilForAllTime的类型,强制转换传递给构造函数的第二个参数:
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("", CType(TmpDS.TotalProfilForAllTime, DataTable))
或:
等等
VB不能清楚地选择最佳的构造函数重载,因此您必须向编译器提供一些帮助。有关可能的第二个参数类型,请参见此链接。
这是VB代码中的一个常见问题,因为VB对解释对象类型不是很严格——它允许使用一种对象类型来代替另一种对象类型,特别是在选项strict Off的情况下。TmpDS的类型是什么。TotalProfilForAllTime?TotalProfilForAllTime是tableadapter,TmpDS。Dim TmpDS是否为新的CPDB
Dim RDS As New Microsoft.Reporting.WinForms.ReportDataSource("", CType(TmpDS.TotalProfilForAllTime, IEnumerable))