用于存储过程的{s}数据源的

时间:2018-03-05 05:13:28

标签: c# asp.net sqldatasource

我有SqlDataSource并希望根据查询字符串对其进行过滤。但是,使用SelectParameters / QueryStringParameter时,它似乎无法将值传递给存储过程。

数据源的配置如下:

<asp:SqlDataSource runat="server" ID="sqlGetDetails"
     ConnectionString='<%$ ConnectionStrings:SqlDbConnectionString.ConnectionString %>'
     SelectCommand= "GetDetails" SelectCommandType="StoredProcedure">
     <asp:SelectParameters>
         <asp:QueryStringParameter Name="AppID" QueryStringField="AppID" DbType="String" Direction="Input" DefaultValue="" ConvertEmptyStringToNull="true"/>
     </asp:SelectParameters>
</asp:SqlDataSource>

失败并显示错误:

  

程序或功能&#39; GetDetails&#39;期望参数&#39; @ AppID&#39;,未提供

使用以下代码创建存储过程:

CREATE PROCEDURE [dbo].[GetDetails]
    @AppID NCHAR(40)
AS
BEGIN
    SELECT * 
    FROM dbo.Details 
    WHERE dbo.Details.AppID = @AppID
END
GO

堆栈追踪:

  

[SqlException(0x80131904):过程或函数&#39; GetDetails&#39;期望&gt;参数&#39; @ AppID&#39;,这是未提供的。]&gt; System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action 1 wrapCloseInAction) +2444190 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction)   5775712 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔callerHasConnectionLock,布尔asyncClose)285 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand的cmdHandler,SqlDataReader的数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,布尔&安培; dataReady)+4169 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()+58 System.Data.SqlClient.SqlDataReader.get_MetaData()+89 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString,Boolean isInternal,Boolean forDescribeParameterEncryption)+409 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async,Int32 timeout,Task&amp; task,Boolean asyncWrite,Boolean inRetry,SqlDataReader ds,Boolean describeParameterEncryptionRequest)+2127 System.Data.SqlClient.Sql Command.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,TaskCompletionSource`1完成,Int32超时,任务&amp;任务,布尔&amp; usedCache,Boolean asyncWrite,Boolean inRetry)+911 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)+64 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,String method) +240 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)+41 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)+12 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset ,DataTable [] datatables,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand command,CommandBehavior behavior)+139 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand command,CommandBehavior behavior )+136 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,String srcTable)+86 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArgu) ments arguments)+1474 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,DataSourceViewSelectCallback callback)+22 System.Web.UI.WebControls.DataBoundControl.PerformSelect()+ 143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind( )+74 System.Web.UI.WebControls.GridView.DataBind()+ 9 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()+ 114 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()   +75 System.Web.UI.Control.EnsureChildControls()+92 System.Web.UI.Control.PreRenderRecursiveInternal()+42 System.Web.UI.Control.PreRenderRecursiveInternal()+ 160 System.Web.UI.Control.PreRenderRecursiveInternal ()+160 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   883

1 个答案:

答案 0 :(得分:0)

您的SelectCommand必须如下所示:

From:

SelectCommand= "GetDetails"

To:

SelectCommand= "GetDetails 12"

12用作参数。

如果你能传递像

这样的话,我从未尝试过
SelectCommand= "GetDetails AppID//Serve as the value".. Just think about it.