问题
When I run my project,the following error message is displayed:
The call is ambiguous between the following methods or properties: 'Microsoft.Reporting.WinForms.ReportDataSource.ReportDataSource(string, System.Collections.IEnumerable)' and 'Microsoft.Reporting.WinForms.ReportDataSource.ReportDataSource(string, System.Data.DataTable).
Why?
firstReportDBDataContext dc = new firstReportDBDataContext();
private void Form1_Load(object sender, EventArgs e)
{
dsFirstReport.dtLoaiHangDataTable dt = new dsFirstReport.dtLoaiHangDataTable();
var query = from a in dc.tblLoaiHangHoas
select a;
foreach (tblLoaiHangHoa a in query)
{
dt.Rows.Add(a.MaLoai, a.TenLoai);
}
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsFirstReport_DataSet1",dt));
this.reportViewer1.RefreshReport();
}
回答1:
From the error message, it's clear that the type dsFirstReport.dtLoaiHangDataTable
inherits the DataTable
type and implements IEnumerable
.
You can resolve the ambiguity for the compiler by casting the parameter to one or the other. E.g.:
reportViewer1.LocalReport.DataSources.Add(
new ReportDataSource("dsFirstReport_DataSet1", (IEnumerable)dt));
来源:https://stackoverflow.com/questions/26931794/error-the-call-is-ambiguous-between-the-following-methods-or-properties