ObjectDataSource could not find a non-generic method

I am using the objectdatasource control and gridview control to display,insert,delete and update data about categories in sql express database.The categoies in the database are being displayed correctly but when i try to insert a new category and click the Add button in the gridview control footer thats when the error occurs

Error Message:
ObjectDataSource ‘odsCategories’ could not find a non-generic method ‘InsertCategory’ that has parameters: categoryName, categoryName1
.

My GridView is as follows:

<asp:GridView ID=“gvCategories” Width =“50%” runat =“server” DataSourceID =“odsCategories” AutoGenerateColumns =“False” OnRowCancelingEdit =“gvCategories_RowCancelingEdit” OnRowEditing =“gvCategories_RowEditing” DataKeyNames =“CategoryID”
OnRowUpdating =“gvCategories_RowUpdating” OnRowUpdated =“gvCategories_RowUpdated” OnRowDeleting =“gvCategories_RowDeleting”
ShowFooter =“True” OnRowCommand =“gvCategories_RowCommand” >
<Columns >
<asp:CommandField ShowDeleteButton=“True” />
<asp:CommandField ShowEditButton =“True” />
<asp:TemplateField HeaderText =“CategoryId” >
<ItemTemplate>
<asp:Label ID=“lblCategoryId” runat =“server” Text =‘<%#Bind(“categoryId”)%>’></asp:Label>
</ItemTemplate>
<FooterTemplate >
<asp:Button ID=“btnAdd” runat =“server” CommandName =“AddCategory” Text =“Add” />
</FooterTemplate>
</asp:TemplateField>

    &lt;asp:TemplateField HeaderText ="Category Name"&gt;
        &lt;ItemTemplate &gt;
            &lt;asp:Label ID="lblcategoryName" runat ="server" Text ='&lt;%#Eval("categoryName")%&gt;' /&gt;
        &lt;/ItemTemplate&gt;
        &lt;EditItemTemplate &gt;
            &lt;asp:TextBox id="txtcategoryName" runat ="server" Text ='&lt;%#Eval("categoryName")%&gt;' /&gt;
        &lt;/EditItemTemplate&gt;
        &lt;FooterTemplate &gt;
            &lt;asp:TextBox ID="txtAddCategoryName" runat ="server" Width ="300px" /&gt;
        &lt;/FooterTemplate&gt;
    &lt;/asp:TemplateField&gt;
 &lt;/Columns&gt;

</asp:GridView>

My ObjectDatasource control is as follows:

<asp:ObjectDataSource ID=“odsCategories” runat =“server”
TypeName =“Category”
SelectMethod =“GetAllCategories”
DeleteMethod =“DeleteCategory”
UpdateMethod =“UpdateCategory”
InsertMethod =“InsertCategory”>
<DeleteParameters>
<asp:Parameter Name=“categoryId” Type=“Int32” />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name=“categoryName” Type=“String” />
<asp:Parameter Name =“categoryId” Type =“int32” />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name=“categoryName” Type=“String” />
</InsertParameters>
</asp:ObjectDataSource>

The error is being raised by the RowCommand method which is as follows

protected void gvCategories_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == “AddCategory”)
{
string catName = ((TextBox)gvCategories.FooterRow.FindControl(“txtAddCategoryName”)).Text;
odsCategories.InsertParameters.Add(“categoryName”,catName );
odsCategories.Insert();
}

}

If it helps the inserting method in the Category class is as follows:

public static void InsertCategory(string categoryName)
{
using (SqlConnection conn = new SqlConnection(Helpers.GetConnectionString()))
{

            SqlCommand myCommand = new SqlCommand("sproc_InsertCategory", conn);
            myCommand.Parameters.AddWithValue("@categoryName", categoryName);
            conn.Open();
            myCommand.ExecuteNonQuery();
            conn.Close();

        }

HELP PLEASE,I AM PULLING MY HAIR OUT

THANKS IN ADVANCE.

parameters: categoryName, categoryName1.

The answer is right in front of you. You are adding a parameter it already has, so it cannot find an overload with two parameters. Make sense?

It certainly does.
Thanks a lot.

Hi tawanda,

I had the same problem and blogged about it in codersbarn.com.

I came up with a hack to avoid setting the parameter(s) declaratively:

&lt;asp:ObjectDataSource ID="sourceEvents" runat="server"
    TypeName="MBID.App_Code.Business.MBID_Business" SelectMethod="GetEventsByMonth"&gt;

protected void EventsCalendar_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
eventsGrid.PageIndex = 0;
DateTime startDate = new DateTime(e.NewDate.Year, e.NewDate.Month, 1);

        int daysInMonth = DateTime.DaysInMonth(e.NewDate.Year, e.NewDate.Month);
        DateTime endDate = new DateTime(e.NewDate.Year, e.NewDate.Month, daysInMonth);

        // Manually remove any select parameters from ParameterCollection
        sourceEvents.SelectParameters.Remove(sourceEvents.SelectParameters["startDate"]);
        sourceEvents.SelectParameters.Remove(sourceEvents.SelectParameters["endDate"]);

        // Manually add the new select parameters for DB call
        sourceEvents.SelectParameters.Add("startDate", startDate.ToShortDateString());
        sourceEvents.SelectParameters.Add("endDate", endDate.ToShortDateString());

        mbidBiz.GetEventsByMonth(startDate, endDate);
    }

Anthony