简体   繁体   English

过程或函数***指定了太多参数

[英]Procedure or function *** has too many arguments specified

Whenever I try to insert something into my database, I get this error: 每当我尝试将某些内容插入数据库时​​,都会出现此错误:

Procedure or function sp_Customer_Insert has too many arguments specified. 过程或函数sp_Customer_Insert指定的参数过多。

Tried to search for help online but couldn't find anything helpful. 尝试在线搜索帮助,但找不到任何有用的信息。

EDIT: I deleted p_cust_id from insert parameters, but it still gives the same error, help please I really don't see what I'm doing wrong 编辑:我从插入参数中删除了p_cust_id ,但它仍然给出相同的错误,请帮助我真的看不到我在做什么错

Stored procedure: 存储过程:

ALTER PROCEDURE [dbo].[sp_Customer_Insert]
 @p_cust_name nvarchar(50)
,@p_cust_address nvarchar(50)
,@p_cust_city nvarchar(50)
,@p_cust_state nvarchar(5)
,@p_cust_zip nvarchar(10)
,@p_cust_country nvarchar(50)
,@p_cust_contact nvarchar(50)
,@p_cust_email  nvarchar(255)
,@p_cust_birthday datetime
AS
BEGIN

INSERT INTO customers
       (cust_name
       ,cust_address
       ,cust_city
       ,cust_state
       ,cust_zip
       ,cust_country
       ,cust_contact
       ,cust_email
       ,cust_birthday)
 VALUES
       (@p_cust_name
       ,@p_cust_address
       ,@p_cust_city 
       ,@p_cust_state
       ,@p_cust_zip
       ,@p_cust_country
       ,@p_cust_contact
       ,@p_cust_email
       ,@p_cust_birthday
       );
END;

ASP code: ASP代码:

<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" Height="50px" Width="223px" AutoGenerateRows="False" DataKeyNames="cust_id">
        <Fields>
            <asp:BoundField DataField="cust_id" HeaderText="cust_id" InsertVisible="False" ReadOnly="True" SortExpression="cust_id" />
            <asp:BoundField DataField="cust_name" HeaderText="cust_name" SortExpression="cust_name" />
            <asp:BoundField DataField="cust_address" HeaderText="cust_address" SortExpression="cust_address" />
            <asp:BoundField DataField="cust_city" HeaderText="cust_city" SortExpression="cust_city" />
            <asp:BoundField DataField="cust_state" HeaderText="cust_state" SortExpression="cust_state" />
            <asp:BoundField DataField="cust_zip" HeaderText="cust_zip" SortExpression="cust_zip" />
            <asp:BoundField DataField="cust_country" HeaderText="cust_country" SortExpression="cust_country" />
            <asp:BoundField DataField="cust_contact" HeaderText="cust_contact" SortExpression="cust_contact" />
            <asp:BoundField DataField="cust_email" HeaderText="cust_email" SortExpression="cust_email" />
            <asp:BoundField DataField="cust_birthday" HeaderText="cust_birthday" SortExpression="cust_birthday" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CrashCourseConnectionString %>" InsertCommand="sp_Customer_Insert" InsertCommandType="StoredProcedure" SelectCommand="sp_CustomerByID" SelectCommandType="StoredProcedure">
        <InsertParameters>
            <asp:Parameter Name="p_cust_name" Type="String" />
            <asp:Parameter Name="p_cust_address" Type="String" />
            <asp:Parameter Name="p_cust_city" Type="String" />
            <asp:Parameter Name="p_cust_state" Type="String" />
            <asp:Parameter Name="p_cust_zip" Type="String" />
            <asp:Parameter Name="p_cust_country" Type="String" />
            <asp:Parameter Name="p_cust_contact" Type="String" />
            <asp:Parameter Name="p_cust_email" Type="String" />
            <asp:Parameter Name="p_cust_birthday" Type="DateTime" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlCustomers" Name="cust_id" PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

C# C#

public static DataTable InsertCustomer(string Name, string Address, string City, string State, string Zip, string Country, string Contact, string Email, DateTime BDay)
{
        DataTable DT = new DataTable();

        SqlDataAdapter DA = new SqlDataAdapter("sp_Customer_Insert", CData.CData.GetConnection());

        DA.SelectCommand.CommandType = CommandType.StoredProcedure;

        DA.SelectCommand.Parameters.AddWithValue("@p_cust_name", Name);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_address", Address);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_city", City);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_state", State);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_zip", Zip);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_country", Country);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_contact", Contact);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_email", Email);
        DA.SelectCommand.Parameters.AddWithValue("@p_cust_birthday", BDay);

        return DT;

Can someone help? 有人可以帮忙吗?

I don't see what I'm doing wrong. 我看不到我在做什么错。

Since there's no @p_cust_id parameter in sp_Customer_Insert , you need to remove <asp:Parameter Name="p_cust_id" Type="Int32" /> from <InsertParameters> : 由于@p_cust_id中没有@p_cust_id参数, sp_Customer_Insert需要从<InsertParameters>删除<asp:Parameter Name="p_cust_id" Type="Int32" /> <InsertParameters>

<InsertParameters>
    <asp:Parameter Name="p_cust_name" Type="String" />
    <asp:Parameter Name="p_cust_address" Type="String" />
    <asp:Parameter Name="p_cust_city" Type="String" />
    <asp:Parameter Name="p_cust_state" Type="String" />
    <asp:Parameter Name="p_cust_zip" Type="String" />
    <asp:Parameter Name="p_cust_country" Type="String" />
    <asp:Parameter Name="p_cust_contact" Type="String" />
    <asp:Parameter Name="p_cust_email" Type="String" />
    <asp:Parameter Name="p_cust_birthday" Type="DateTime" />
</InsertParameters>

We get this error when we try to insert more parameters than we have defined 当我们尝试插入比我们定义的更多的参数时,会出现此错误

As in your .aspx page code in you have defined one extra parameter ie 就像在您的.aspx页面代码中一样,您定义了一个额外的参数,即

<asp:Parameter Name="p_cust_id" Type="Int32" />

Remove this line as you are not inserting id field. 由于您没有插入ID字段,因此请删除此行。

您需要从ASP文件中的<InsertParameters>中删除<asp:Parameter Name="p_cust_id" Type="Int32" />

I had a similar problem which turned out to be due to the use of a DataKeyName which was not used as a parameter to my (Update) Stored Procedure. 我有一个类似的问题,原来是由于使用了DataKeyName引起的,该DataKeyName未被用作(更新)存储过程的参数。 It seemed to be included with the update parameters collection although I could not find any documentation to explain why. 它似乎包含在更新参数集合中,尽管我找不到任何文档来解释原因。 I corrected the problem at the time by adding the DataKey as an (unused) parameter in the Stored Procedure. 我通过在存储过程中将DataKey添加为(未使用的)参数来解决了该问题。 I did not need to add to the updateParameters collection. 我不需要添加到updateParameters集合。

This was just a temporary fix to test if this would resolve the issue - in the end I recoded the page so I did not use a DataKey. 这只是测试是否可以解决问题的临时解决方案-最后,我重新编码了页面,因此没有使用DataKey。

In this instance I would try adding a declaration of cust_id to sp_Customer_Insert . 在这种情况下,我将尝试在sp_Customer_Insert添加一个cust_id声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM