ObjectDataSource could not find a non-generic method

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>

My DAL code is:

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 this my optional parameter causing the problem? How can I get around this? Is it possible to have optional parameters with declarative ASP.NET code?

+3
source share
2 answers

add method:

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

and check if it works?

+3
source

You can use SelectParametersas follows:

<asp:ObjectDataSource id="srcBrokers" TypeName="DatabaseComponent.DBUtil" SelectMethod="GetBrokers" runat="server">
    <SelectParameters>
    <asp:Parameter Name="hasImport" Type="Empty" />
    <SelectParameters>
</asp:ObjectDataSource>
0
source

Source: https://habr.com/ru/post/1781246/


All Articles