C# 过程或函数指定的参数太多或根本无法传递
我正在试图弄清楚为什么我的update命令不起作用。它似乎与GridView上的DataKeys字段有关。这就是为什么我让delete函数在不指定delete参数的情况下工作,因为它们与要从gridview和sql数据源中删除的存储过程一致。然而,我的网格视图更新功能需要更多的参数。所以我传递了所有的值,得到了名义上的错误。如果我删除gridview更新部分中的所有参数,并传入其背后的代码,则表示根本没有传递值 我只是不明白如何添加参数。我尝试了SqlDataSource2.DeleteParameters。Add@Product产品或者在代码隐藏中使用sql语句,但它们似乎不起作用。有人能帮我吗C# 过程或函数指定的参数太多或根本无法传递,c#,sql,asp.net,sql-server,gridview,C#,Sql,Asp.net,Sql Server,Gridview,我正在试图弄清楚为什么我的update命令不起作用。它似乎与GridView上的DataKeys字段有关。这就是为什么我让delete函数在不指定delete参数的情况下工作,因为它们与要从gridview和sql数据源中删除的存储过程一致。然而,我的网格视图更新功能需要更多的参数。所以我传递了所有的值,得到了名义上的错误。如果我删除gridview更新部分中的所有参数,并传入其背后的代码,则表示根本没有传递值 我只是不明白如何添加参数。我尝试了SqlDataSource2.DeletePara
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestAdamConnectionString %>" SelectCommand="SELECT * FROM [TestRedo]"
DeleteCommandType="StoredProcedure" DeleteCommand="deleteFromGrid" OnUpdating="SqlDataSource2_Updating" UpdateCommandType="StoredProcedure" UpdateCommand="updateValues">
<UpdateParameters>
<asp:Parameter Name ="@Product" />
<asp:Parameter Name ="@Type" />
<asp:Parameter Name ="@2016AccCode" />
<asp:Parameter Name ="@2017BudgetAccCode" />
<asp:Parameter Name ="@BusinessUnit" />
<asp:Parameter Name ="@Group" />
<asp:Parameter Name ="@TIAYTD" />
<asp:Parameter Name ="@InvoiceDate" />
<asp:Parameter Name ="@RenewPeriod" />
<asp:Parameter Name ="@AdvancedCancel" />
<asp:Parameter Name ="@Renew" />
<asp:Parameter Name ="@Notes" />
<asp:Parameter Name ="@DueSoon" />
<asp:Parameter Name ="@jOrS" />
</UpdateParameters>
</asp:SqlDataSource>
ALTER PROCEDURE [dbo].[updateValues]
-- Add the parameters for the stored procedure here
@Vendor nvarchar(max),
@Product nvarchar(max),
@Type nvarchar(max),
@2016AccCode nvarchar(max),
@2017BudgetAccCode nvarchar(max),
@BusinessUnit nvarchar(max),
@Group nvarchar(max),
@TIAYTD nvarchar(max),
@InvoiceDate nvarchar(max),
@RenewPeriod nvarchar(max),
@Expiration datetime,
@AdvancedCancel nvarchar(max),
@ActionReq datetime,
@Renew nvarchar(max),
@Notes nvarchar(max),
@DueSoon nvarchar(max),
@jOrS nvarchar(max)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE TestRedo
SET [Product/Service] = @Product,
[Type] = @Type,
[2016AccCode] = @2016AccCode,
[2017BudgetAccCode] = @2017BudgetAccCode,
BusinessUnit = @BusinessUnit,
[Group] = @Group,
TIAYTD = @TIAYTD,
InvoiceDate = @InvoiceDate,
RenewPeriod = @RenewPeriod,
AdvancedCancel = @AdvancedCancel,
Renew = @Renew,
Notes = @Notes,
DueSoon = @DueSoon,
[John/Steve] = @jOrS
WHERE Vendor = @Vendor AND Expiration = @Expiration AND ActionReq = @ActionReq
END
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ActionReq, Vendor, Expiration" DataSourceID="SqlDataSource2" AutoGenerateColumns="True" HorizontalAlign="Center"
Width="95%" AllowSorting="True" AllowCustomPaging="False" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ForeColor="Black"
GridLines="Horizontal" HeaderStyle-CssClass="pagination" SortedDescendingHeaderStyle-VerticalAlign="NotSet" CellPadding="5" RowStyle-HorizontalAlign="Center" RowStyle-VerticalAlign="Middle"
OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound" SelectedRowStyle-HorizontalAlign="NotSet" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="UpdateBtn" runat="server" Text="Edit" CommandName="Edit"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkUpdate" runat="server" Text="Update" CommandName="Update"/>
<asp:LinkButton ID="LinkCancel" runat="server" Text="Cancel" CommandName="Cancel"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="DeleteBtn" runat="server" CommandName="Delete"
OnClientClick="return isDelete();">Delete
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
在过程中,您将供应商作为参数,但它不是数据源中UpdateParameters的一部分。你真的需要nvarcharmax吗?您熟悉sql server中的数据类型吗?一切都不应该是nvarcharmax。他们这样做的原因是因为我所处理的信息的性质;这是一张测试表。只有3列,Action、Vendor和Expiration必须不同,因为我需要date功能。我可以稍后修复数据类型。即使更新参数字段中有这些列,它仍然表示太多。我相信使用DataKeys这些值会自动传递。ASP.net会自动将DataKey DataKeyNames=ActionReq、Vendor、Expiration作为参数添加/发送到您的命令中。您可能应该在代码隐藏中编写一个处理程序函数,这样您就可以控制发送的参数,或者您可以修改存储过程以接受附加参数Show事件处理程序会启动吗?我有GridView行更新和sql数据源更新。我会使用哪一个?在过程中有供应商作为参数,但它不是数据源中UpdateParameters的一部分。你真的需要nvarcharmax吗?您熟悉sql server中的数据类型吗?一切都不应该是nvarcharmax。他们这样做的原因是因为我所处理的信息的性质;这是一张测试表。只有3列,Action、Vendor和Expiration必须不同,因为我需要date功能。我可以稍后修复数据类型。即使更新参数字段中有这些列,它仍然表示太多。我相信使用DataKeys这些值会自动传递。ASP.net会自动将DataKey DataKeyNames=ActionReq、Vendor、Expiration作为参数添加/发送到您的命令中。您可能应该在代码隐藏中编写一个处理程序函数,这样您就可以控制发送的参数,或者您可以修改存储过程以接受附加参数Show事件处理程序会启动吗?我有GridView行更新和sql数据源更新。我会用哪一种?