I have a SqlDataSource
and want to filter it based on query string. However using SelectParameters
/ QueryStringParameter
, it doesn't seem to pass the value to the stored procedure.
The data source is configured like this:
<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>
It fails with error:
Procedure or function 'GetDetails' expects parameter '@AppID', which was not supplied
The stored procedure was created with code like this:
CREATE PROCEDURE [dbo].[GetDetails]
@AppID NCHAR(40)
AS
BEGIN
SELECT *
FROM dbo.Details
WHERE dbo.Details.AppID = @AppID
END
GO
Stack trace:
[SqlException (0x80131904): Procedure or function 'GetDetails' expects >parameter '@AppID', which was not supplied.] >System.Data.SqlClient.SqlConnection.OnError(SqlException exception, 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, Boolean callerHasConnectionLock, Boolean asyncClose) +285 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& 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& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2127 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& 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(DataSourceSelectArguments 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