ObjectDataSource找不到非通用方法

ObjectDataSource找不到非通用方法

本文介绍了ObjectDataSource找不到非通用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个ASP.NET代码:

I have this ASP.NET code:

<asp:DropDownList
    ID="ddlBrokers"
    runat="server"
    AutoPostBack="true"
    DataSourceID="srcBrokers"
    DataTextField="broker"
    DataValueField="brokerId"
/>

<asp:ObjectDataSource
    id="srcBrokers"
    TypeName="DatabaseComponent.DBUtil"
    SelectMethod="GetBrokers"
    runat="server">
</asp:ObjectDataSource>

我的DAL代码:

public DataTable GetBrokers(bool? hasImport=null)
{
    SqlCommand cmd = new SqlCommand("usp_GetBrokers");
    if (hasImport.HasValue)
        cmd.Parameters.AddWithValue("@hasImport", hasImport);
    return FillDataTable(cmd, "brokers");
}

加载表单时出现此错误:

When the form loads I get this error:

ObjectDataSource 'srcBrokers' could not find a non-generic method 'GetBrokers' that has no parameters.

是我的可选参数导致了此问题吗?我该如何解决?

Is it my optional parameter that is causing the problem? How can I workaround this? Is it possible to have optional parameters with declarative ASP.NET code?

推荐答案

添加方法:

public DataTable GetBrokers() {
              return GetBrokers(null);
}

然后检查是否可行?

这篇关于ObjectDataSource找不到非通用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:51