Error: “The call is ambiguous between the following methods or properties”?

最后都变了- 提交于 2019-12-11 10:06:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!