ObjectDataSource 插入和更新方法错误
我正在开发 asp.net 3.5 项目。
当我想使用 DetailsView 插入时,发生了此错误:
错误:ObjectDataSource“ObjectDataSource2”找不到具有参数:CITY_NAME 的非通用方法“AddCity”。
<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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如下更新您的 ObjectDataSource 标记,它应该可以工作。您在插入参数标签中给出了错误的参数名称。
Update your ObjectDataSource markup as below and it should work. You have given wrong parameter name in the Insert parameters tag.
您是否尝试在声明 objectdatasource 时将 Name="CITY_NAME" 更改为 Name="cityname" ,以便它与您的方法中的签名匹配?
Have you tried to change Name="CITY_NAME" to Name="cityname" when declaring the objectdatasource so that it matches the signature in your method?