ObjectDataSource控件不是要求插入方法时,它有额外的参数 [英] ObjectDataSource not calling Insert method when it has extra parameters
问题描述
我新的ASP.NET和我想实现一个自定义的ObjectDataSource插入方法。
默认的业务方法工作正常(与单个对象参数)。然而,当我添加一个额外的参数,该商业方法不会被调用。
下面是我的code - 插入()总是被调用,但InsertWithParams()从来不会
。 //业务层
公共类为MyObject
{
公众为MyObject(){}
公共字符串美孚{搞定;组;}
}命名空间MyLogic {
公共静态插入(为MyObject米)
{
// ...做数据库插入
}公共静态InsertWithParams(为MyObject男,串P)
{
// ...做更多的花哨DB插入
}
} // MyLogic
鉴于以下的ObjectDataSource声明
InsertWithParams和MyObjectDS_Inserting永远不会被调用。
然而相反,若指定MyLogic.Insert,它得到的与事件一起叫。另外,如果我删除InsertWithParams p参数,它被调用。
< ASP:ObjectDataSource控件=服务器ID =MyObjectDS
类型名=Business.MyLogic
DataObjectTypeName =Business.MyObject
InsertMethod =InsertWithParams
OnInserting =MyObjectDS_Inserting
>
< InsertParameters>
< ASP:参数名称=M型=对象/>
< ASP:参数名称=P类型=字符串/>
< / InsertParameters>
< / ASP:ObjectDataSource控件>
所以看起来在这种情况下,我不能参数添加到一个ObjectDataSource插入方法。
添加或删除宣布InsertParameters似乎不有所作为。
我也遇到了麻烦插入记录,但是,我发现测试了一段时间,google了一下后,如果您指定的ObjectDataSource'DataObjectTypeName'参数,InsertParameters被忽略。所以,我只是不指定,它为我工作。
块引用>从这里开始:<一href=\"http://www.velocityreviews.com/forums/t297725-objectdatasource-has-no-values-to-insert-error.html\" rel=\"nofollow\">http://www.velocityreviews.com/forums/t297725-objectdatasource-has-no-values-to-insert-error.html
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.
解决方案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
这篇关于ObjectDataSource控件不是要求插入方法时,它有额外的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!