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();
}
From the error message, it's clear that the type
dsFirstReport.dtLoaiHangDataTable
inherits theDataTable
type and implementsIEnumerable
.You can resolve the ambiguity for the compiler by casting the parameter to one or the other. E.g.: