我有一个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>它错误地失败了:
过程或函数'GetDetails‘期望参数'@AppID',该参数没有提供
存储过程是用如下代码创建的:
CREATE PROCEDURE [dbo].[GetDetails]
@AppID NCHAR(40)
AS
BEGIN
SELECT *
FROM dbo.Details
WHERE dbo.Details.AppID = @AppID
END
GO堆栈跟踪:
SqlException (0x80131904):未提供的过程或函数“GetDetails”期望>参数@AppID。>System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔型breakConnection,动作
1 wrapCloseInAction) +2444190 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5775712 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔型callerHasConnectionLock,布尔型asyncClose) +285 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet cmdHandler,Boolean& ) +4169 +58 +89 ds,,String,Boolean,+409 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、runBehavior runBehavior、布尔returnStream、布尔异步、Int32超时值、任务与任务、布尔asyncWrite、布尔inRetry、SqlDataReader ds、Boolean ) +2127 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、runBehavior RunBehavior、Boolean、String方法、TaskCompletionSource`1 `1完成、cmdBehavior超时、任务与任务、布尔与反求、布尔定界、911 en22#、en24#、、String方法) +64行为,+240 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行为) +41 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior行为) +12 System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集,DataTable[]数据集,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior behavior) +139 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String,命令,behavior) +136 (en23#,+86 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments参数) +1474 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments参数,+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系统.Web.UI.Control.PreRenderRecursiveInternal() +160 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +883
发布于 2018-03-05 05:35:22
您的SelectCommand必须如下所示:
From:
SelectCommand= "GetDetails"
To:
SelectCommand= "GetDetails 12"12用作参数。
我从来没试过如果你能通过
SelectCommand= "GetDetails AppID//Serve as the value".. Just think about it.https://stackoverflow.com/questions/49103846
复制相似问题