转到下一页后,带有DataPager的ASP.NET ListView引发错误

时间:2010-09-07 04:48:08

标签: asp.net listview datapager

我在使用DataPager的ListView中遇到了问题。

我有SqlDataSource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ADSConnectionString %>" 
    SelectCommand="usp_posts_getall" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

它在ListView中被绑定了。我将DataPager中的PageSize设置为5,因此导航到下一页后。

抛出错误

Procedure or function usp_posts_getall has too many arguments specified

在我的 usp_posts_getall 中,我只有1个参数

@thisCategoryID int

出了什么问题?

[SqlException(0x80131904):过程或函数usp_posts_getall指定的参数太多。]    System.Data.SqlClient.SqlConnection.OnError(SqlException exception,Boolean breakConnection)+1951450    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection)+4849003    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)+194    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+2394    System.Data.SqlClient.SqlDataReader.ConsumeMetaData()+ 33    System.Data.SqlClient.SqlDataReader.get_MetaData()+ 83    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)+297    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)+954    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,DbAsyncResult result)+162    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)+32    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,String method)+141    System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)+12    System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)+10    System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集,DataTable [] datatables,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior行为)+130    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand command,CommandBehavior behavior)+287    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,String srcTable)+92    System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)+1297    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments参数,DataSourceViewSelectCallback回调)+19    System.Web.UI.WebControls.DataBoundControl.PerformSelect()+ 142    System.Web.UI.WebControls.ListView.PerformSelect()+57    System.Web.UI.WebControls.BaseDataBoundControl.DataBind()+73    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()+82    System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)+22    System.Web.UI.Control.PreRenderRecursiveInternal()+ 80    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Control.PreRenderRecursiveInternal()+171    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+842

1 个答案:

答案 0 :(得分:1)

好的抱歉,

我忘了清除SelectParameters,因为在我的Page_Load中,我有这段代码:

        Parameter param = new Parameter();
        param.Name = "thisCategoryID";
        param.Type = TypeCode.Int32;
        param.DefaultValue = SelectedCategoryID.ToString();

        SqlDataSource1.SelectParameters.Clear();  // <<--- and I forgot this
        SqlDataSource1.SelectParameters.Add(param);

现在正在使用