错误:“以下方法或属性之间的调用不明确"? [英] Error: "The call is ambiguous between the following methods or properties"?

查看:385
本文介绍了错误:“以下方法或属性之间的调用不明确"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的项目时,显示以下错误消息:

When I run my project,the following error message is displayed:

以下方法或属性之间的调用不明确:Microsoft.Reporting.WinForms.ReportDataSource.ReportDataSource(string, System.Collections.IEnumerable)"和Microsoft.Reporting.WinForms.ReportDataSource.ReportDataSource(string, System.数据.数据表).

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).

为什么?

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();

    }

推荐答案

从报错信息可以看出,dsFirstReport.dtLoaiHangDataTable 类型继承了DataTable 类型并实现IEnumerable.

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));

这篇关于错误:“以下方法或属性之间的调用不明确"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆