gpt4 book ai didi

c# - 在 ASPX 页面上获取 'too many parameters passed' 到存储过程

转载 作者:行者123 更新时间:2023-12-02 01:21:08 24 4
gpt4 key购买 nike

我无法弄清楚这个错误。我在 ASPX 页面上有一个网格,用于显示 SQL Server 2008 数据库中存储过程的数据。当页面加载时,我收到以下错误:

"Procedure or function <sp_name> has too many arguments specified."

这是网格和数据源的代码:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" ShowFooter="True" OnRowDataBound="GridView1_RowDataBound"
AllowSorting="True">
<Columns>
<asp:BoundField DataField="MerchantID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="MerchantID" />
<asp:BoundField DataField="MerchantName" HeaderText="Merchant" SortExpression="MerchantName" />
<asp:BoundField DataField="RapidTuitionID" HeaderText="RapidTuition ID" SortExpression="RapidTuitionID" />
<asp:BoundField DataField="DateCreated" HeaderText="Enrolled" SortExpression="DateCreated" />
<asp:TemplateField HeaderText="Commands">
<ItemTemplate>
<asp:LinkButton ID="ImpersonateUserLinkButton" runat="server" OnClick="Command_Click"
CommandName="impersonate" CommandArgument='<%# Eval("MerchantID") %>' CssClass="table_command">Impersonate</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No data to display.
</EmptyDataTemplate>
<PagerStyle CssClass="pager" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Development %>"
SelectCommand="sp_GatewayMerchants" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="PromotionPlaceHolderTop$StartDate" Name="StartDate"
DefaultValue="1/1/2010" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="PromotionPlaceHolderTop$EndDate" Name="EndDate"
DefaultValue="12/31/2010" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="PromotionPlaceHolderTop$StatusActive" DefaultValue="true"
Name="StatusActive" PropertyName="Checked" Type="Boolean" />
<asp:ControlParameter ControlID="PromotionPlaceHolderTop$StatusDeactive" DefaultValue="true"
Name="StatusDeactive" PropertyName="Checked" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>

这是存储过程的代码:

ALTER PROCEDURE [dbo].[sp_GatewayMerchants] 
-- Add the parameters for the stored procedure here
@StartDate DateTime,
@EndDate DateTime,
@StatusActive bit,
@StatusDeactive bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT
m.MerchantID AS [ID],
m.MerchantName,
CASE m.StatusFlag WHEN 1 THEN 'Active' ELSE 'Deactive' END AS [Status],
m.RapidTuitionID,
m.DateCreated
FROM
Merchant m
WHERE
(CONVERT(varchar,m.DateCreated,112) BETWEEN CONVERT(varchar,CONVERT(DATETIME,@StartDate,101),112) AND CONVERT(varchar,CONVERT(DATETIME,@EndDate,101),112))
AND
(
(@StatusActive = 1 AND m.StatusFlag = 1)
OR
(@StatusDeactive = 1 AND m.StatusFlag = 0)
)
ORDER BY
m.MerchantName
END

数据源传递 4 个参数,存储过程接受 4 个参数,但是当页面显示时,我收到上述错误。我在这里遗漏了什么吗?

编辑:这是模板列后面的代码。但我不确定这如何导致 SP 出现额外的参数。

        protected void Command_Click(object sender, EventArgs e)
{
var merchantID = Convert.ToInt32(((LinkButton)sender).CommandArgument);

switch (((LinkButton)sender).CommandName)
{
case "impersonate":
var gs = GatewaySession.Parse(Page.User.Identity.Name);
gs.Role = GatewaySession.RoleEnum.Merchant;
gs.MerchantID = merchantID;
gs.CustomerID = -1;

FormsAuthentication.SetAuthCookie(gs.ToString(), false);

Page.Session["MerchantID"] = gs.MerchantID;

Response.Redirect("/Merchant/Default.aspx");
break;
}
}

如果我删除 ASP:LINKBUTTON 代码就可以工作。那么为什么 LINKBUTTON 会导致这种情况呢?

最佳答案

使用 Profiler 并检查哪些参数真正传递给 SP。

关于c# - 在 ASPX 页面上获取 'too many parameters passed' 到存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4314676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com