Error: “The call is ambiguous between the followin

2019-08-05 15:40发布

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条回答
祖国的老花朵
2楼-- · 2019-08-05 16:16

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));
查看更多
登录 后发表回答