Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObjectDataSource could not find a non-generic method

Tags:

c#

asp.net

c#-4.0

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:

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?

like image 795
Mark Allison Avatar asked Jan 02 '26 08:01

Mark Allison


1 Answers

add method:

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

and check is it works?

like image 118
Andrei Andrushkevich Avatar answered Jan 03 '26 21:01

Andrei Andrushkevich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!