【发布时间】:2018-08-12 17:13:42
【问题描述】:
我有一个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,Action
1 wrapCloseInAction) +2444190 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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 ) +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.数据.SqlClient.SqlCommand。 RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String 方法,TaskCompletionSource`1 完成,Int32 超时,Task& 任务,Boolean& usedCache,Boolean asyncWrite,Boolean inRetry)+911 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔返回流,String 方法)+64 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,String 方法)+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 行为)+139 系统.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehav ior 行为)+136 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,String srcTable)+86 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments 参数)+1474 System.Web.UI.DataSourceView.Select( DataSourceSelectArguments 参数,DataSourceViewSelectCallback 回调)+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(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +883
【问题讨论】:
-
你是不是把appid参数放到URL里了?
-
将 Direction="Input" 更改为 Direction="Output" 或尽量保持简单
-
是我尝试的第一件事。我尝试更改为输出它也不起作用。
标签: c# asp.net sqldatasource