ObjectDataSource not calling Insert method when it has extra parameters

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 20:16:05

问题


I'm new to ASP.NET, and I'm trying to implement a custom ObjectDataSource Insert method. The default business method works fine (with a single object parameter). However when I add an extra parameter, the business method does not get called.

Here is my code - Insert() always gets called, but InsertWithParams() never does.

// Business Layer 
public class MyObject
{
  public MyObject() {}
  public string Foo { get; set;}
}

namespace MyLogic {
public static Insert(MyObject m)
{
  // ... do DB insert
}

public static InsertWithParams(MyObject m, string p)
{
  // ... do more fancy DB insert
}
} // MyLogic

Given the following ObjectDataSource declaration, "InsertWithParams" and "MyObjectDS_Inserting" are never called.

However if "MyLogic.Insert" is specified instead, it does get called along with the event. Also If I remove the p parameter from InsertWithParams, it does get called.

<asp:ObjectDataSource runat="server" ID="MyObjectDS"
        TypeName="Business.MyLogic"
        DataObjectTypeName="Business.MyObject"
        InsertMethod="InsertWithParams"
        OnInserting="MyObjectDS_Inserting"
        >
        <InsertParameters>
            <asp:Parameter Name="m" Type="Object" />
            <asp:Parameter Name="p" Type="String" />
        </InsertParameters>
</asp:ObjectDataSource>

So it seems in this case I can't add parameters to an insert method in an ObjectDataSource. Adding or removing declared InsertParameters does not seem to make a difference.


回答1:


I also had trouble inserting record, however, I found out after testing for a while and google a bit, that if your specify 'DataObjectTypeName' parameter in ObjectDataSource, InsertParameters get ignored. So I just don't specify that, and it works for me.

From here: http://www.velocityreviews.com/forums/t297725-objectdatasource-has-no-values-to-insert-error.html



来源:https://stackoverflow.com/questions/2188793/objectdatasource-not-calling-insert-method-when-it-has-extra-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!