views:

140

answers:

2

I m developing asp.net 3.5 project.

When I want to Insert with DetailsView this error occured:

Error : ObjectDataSource 'ObjectDataSource2' could not find a non-generic method 'AddCity' that has parameters: CITY_NAME.

<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetCityByID" UpdateMethod="UpdateCity" InsertMethod="AddCity" TypeName="NOP_CRM.Lib.nop_cities" OldValuesParameterFormatString="original_{0}">
    <SelectParameters>
        <asp:ControlParameter ControlID="GridView1" Name="cityid" PropertyName="SelectedValue" Type="Int32" DefaultValue="1" />
    </SelectParameters>
    <UpdateParameters>                              
        <asp:Parameter Name="CITY_NAME" Type="String" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter Name="CITY_NAME" Type="String" />
    </InsertParameters>                                
</asp:ObjectDataSource>                    

...

public int AddCity(string cityname)
{
    CITY_NAME = cityname;
    Insert();
    return _CITY_ID;            
}        
A: 

Have you tried to change Name="CITY_NAME" to Name="cityname" when declaring the objectdatasource so that it matches the signature in your method?

Geir-Tore Lindsve
+1  A: 

Update your ObjectDataSource markup as below and it should work. You have given wrong parameter name in the Insert parameters tag.

<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetCityByID" UpdateMethod="UpdateCity" InsertMethod="AddCity" TypeName="NOP_CRM.Lib.nop_cities" OldValuesParameterFormatString="original_{0}"> 
    <SelectParameters> 
        <asp:ControlParameter ControlID="GridView1" Name="cityid" PropertyName="SelectedValue" Type="Int32" DefaultValue="1" /> 
    </SelectParameters> 
    <UpdateParameters>                               
        <asp:Parameter Name="CITY_NAME" Type="String" /> 
    </UpdateParameters> 
    <InsertParameters> 
        <asp:Parameter Name="cityname" Type="String" /> 
    </InsertParameters>                                 
</asp:ObjectDataSource>   
this. __curious_geek