ASP.NET2.0中对GridView删除操作时“未能找到带参数的非泛型方法”的解决方案

在ASP.Net中对ObjectDataSource自动配置数据源的[删除]操作的时候,会生成两个字段一个是

OldValuesParameterFormatString="original_{0}"

另外一个是

<DeleteParameters>
                                <asp:Parameter Name="original_XML_ID" Type="Int32" />
                            </DeleteParameters>

这里面OldValuesParameterFormatString是根据你设定的SQL语句中的参数确定的,而Parameter Name却是根据你的业务罗基层中删除函数的第一个参数确定的。
比如,业务逻辑层中你的删除组件是这样定义的,函数中的第一个参数就是ObjectDataSource生成的Parameter Name

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
    public bool DelXML(int original_XML_ID)
    {
        int rowsAffected = Adapter.Delete(original_XML_ID);

        return rowsAffected == 1;
    }


这里要注意的是你BLL中DEL函数中的括弧中的参数名称和SQL中的参数名称如果不一样,则会出现“未能找到带参数的非泛型方法”得奇怪错误。不知道算不算是ASP.NET的BUG不过确实很讨厌。就连微软官方的教程(见www.asp.net)中都没有解决这个BUG。

我在互联网上搜索这个问题的解决方案,没有找到说得比较详细的。幻想曲也发现了类似的这个问题,并提到出了他的解决办法

总之是个普遍的问题呵呵需要大家注意。

4 comments

  1. llj098 说道:

    支持一下~~解决了我的问题~~呵呵

  2. lyhuc 说道:

    顶一下

  3. Fletcher Krase 说道:

    I just want to mention I am very new to blogs and truly liked this web page. Probably I’m likely to bookmark your blog . You definitely come with great articles and reviews. Regards for revealing your website.

  4. Devin Nordmeyer 说道:

    Thanks for your posting. One other thing is that if you are marketing your property alone, one of the concerns you need to be mindful of upfront is when to deal with household inspection accounts. As a FSBO home owner, the key to successfully moving your property as well as saving money on real estate agent commission rates is awareness. The more you are aware of, the softer your property sales effort might be. One area when this is particularly critical is inspection reports.

发表评论

电子邮件地址不会被公开。