“ObjectDataSource1”未能找到带参数的非泛型方法“GetData”: yonghuid, maximumRows, startRowIndex

来源:百度知道 编辑:UC知道 时间:2024/07/02 17:25:41
我用数据库做的数据访问层,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中启用了,有分页效果吗

你启用了分页。

所以它在检索的时候会多带两个参数, 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 )
{ //中间代码省略
}