Mark Allison Mark Allison - 6 days ago 5
C# Question

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:

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?

Answer

add method:

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

and check is it works?

Comments