未能找到不带参数的非泛型方法

 http://localhost:1966/Web/Admin/OrderDetail.aspx

“/Web”应用程序中的服务器错误。
--------------------------------------------------------------------------------

ObjectDataSource“ObjectDataSource1”未能找到不带参数的非泛型方法“GetDetailOrderById”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.InvalidOperationException: ObjectDataSource“ObjectDataSource1”未能找到不带参数的非泛型方法“GetDetailOrderById”。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 

堆栈跟踪:


[InvalidOperationException: ObjectDataSource“ObjectDataSource1”未能找到不带参数的非泛型方法“GetDetailOrderById”。]
   System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(Type type, String methodName, IDictionary allParameters, DataSourceOperation operation) +1329822
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1933
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
---------------------------------------------------------
****************************************************
解决办法1:
****************************************************
ObjectDataSource“ObjectDataSource1”未能找到带参数的非泛型方法

ObjectDataSource的使用的函数最好将变量名和数据库字段名统一,否则可能会出现错误虽然有解决办法,但没必要浪费时间去玩那个,不就是变量名吗,无所谓的啦。如果需要使用ObjectDataSource控件的更新和删除功能,一般是根据主键进行修改的,但是我在使用这个功能的时候,由于把主键这个字段设置为了readonly(主键不能更新),结果传回去的时候主键值就没有了,后来想了个办法,用cookieparam作为主键的来源,在gridview或者detailsview控件更新、删除之前(响应事件)将主键值写入cookie,感觉有点笨,不过功能没什么问题。

我发现自己真的很笨耶,晕死了。想要取回主键ID值,不用cookie那么麻烦去做,虽然可以实现功能,但肯定不好。
下面的方法应该才是正确的方法:
   指定GridView或者DetailsView的 DataKeyNames 属性,比如你的主键ID是ID,则指定DataKeyNames"ID"
在objectdatasource或者其他数据源控件指定参数,如下:

这样就可以传过去了
下面是我的一些代码:
DetailsView :
       

<yyc:SmartGridView ID="SmartGridView1" runat="server" AllowPaging="True" DataKeyNames="UserName"  DataSourceID="ObjectDataSource1" AutoGenerateColumns="False" AutoGenerateDeleteButton="True">
        <Columns>
        <asp:BoundField DataField="UserName" HeaderText="用户名" SortExpression="UserName" ReadOnly="True"/>
        <asp:BoundField DataField="Email" HeaderText="邮箱" SortExpression="Email"/>
        <asp:BoundField DataField="PasswordQuestion" HeaderText="问题" SortExpression="PasswordQuestion" />
        <asp:BoundField DataField="Comment" HeaderText="回答" SortExpression="Comment" />
        <asp:BoundField DataField="IsApproved" HeaderText="是否启用" SortExpression="IsApproved" />
        <asp:BoundField DataField="CreateDate" HeaderText="创建时间" SortExpression="CreateDate" />
        <asp:BoundField DataField="LastLoginDate" HeaderText="上次登录时间" SortExpression="LastLoginDate" />
        <asp:BoundField DataField="LastActivityDate" HeaderText="上次激活时间" SortExpression="LastActivityDate" />
        <asp:BoundField DataField="LastPasswordChangedDate" HeaderText="上次变更密码时间" SortExpression="LastPasswordChangedDate" />
        <asp:BoundField DataField="UserId" HeaderText="用户ID" SortExpression="UserId" />
        <asp:BoundField DataField="IsLockedOut" HeaderText="是否锁定" SortExpression="IsLockedOut" />
        <asp:BoundField DataField="LastLockoutDate" HeaderText="解除锁定时间" SortExpression="LastLockoutDate" />
        <asp:CommandField ShowDeleteButton="True" ButtonType="Button"/>
    </Columns>
</yyc:SmartGridView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetUsers" TypeName="UsersManager" DeleteMethod="DelUser">
       <DeleteParameters>
           <asp:Parameter Name="UserName" Type="String" />
       </DeleteParameters>
   </asp:ObjectDataSource>

业务层代码: 

[DataObjectMethod(DataObjectMethodType.Delete, true)]
public bool DelUser(string UserName)
{
    return Membership.DeleteUser(UserName);
}

****************************************************
解决办法2:
****************************************************
“ObjectDataSource1”未能找到带参数的非泛型方法“GetData”: yonghuid, maximumRows, startRowIndex
 悬赏分:10 - 解决时间:2008-11-10 17:14
我用数据库做的数据访问层,sql语句这样的select id,shijian,fenlei,biaoti from liuyan where yonghuid=@yonghuid order by shijian desc,
objectdatasource这样的<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="liuyanTableAdapters.liuyanTableAdapter" DeleteMethod="Delete" UpdateMethod="Update">
<SelectParameters>
<asp:SessionParameter Name="yonghuid" SessionField="id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

帮我看看哪里错了
问题补充:恩是这个问题,那如果这里不启用分页,而gridview中启用了,有分页效果吗
提问者: shen1830 - 门吏 三级 最佳答案
你启用了分页。

所以它在检索的时候会多带两个参数, startRowIndex 和 maximumRows,用于指定要返回的数据开始行数和最大记录数。
同时它也会试图使用 SelectCountMethod,但你并没有指定。

//补充
大概是没有的,就算是有,它也是把数据全部加载出来,然后再取其中的一部分,并没有达到节约资源的目的。

你可以适当修改你的

liuyanTableAdapters.liuyanTableAdapter.GetData方法的参数来适应这个分页。
同时应该还要提供一个方法来返回查询的记录数。

给你一个相应的例子:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="true" SelectCountMethod="GetLogCount"
SelectMethod="LoadLogs" TypeName="EGovernment.SMS.SMSSendLogs">
<SelectParameters>
<asp:Parameter Name="username" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

其中LoadLogs方法和GetLogCount方法的定义如下:

public static IEnumerable<SMSSendLogEntity> LoadLogs( string username, int startRowIndex, int maximumRows )
{ //中间代码省略
}
public static int GetLogCount( string username )
{//中间代码省略
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值