Procedure or function SPInsertIndividual has too many arguments specified

Last Reply on Sep 19, 2014 02:50 AM By Mudassar

Posted on Sep 19, 2014 01:47 AM

Can anyone help, I am having trouble posting a form to a Table in my database. I am getting a ERROR "Procedure or function SPInsertIndividual has too many arguments specified.", Can anyone help it would be very much appreciated.

My SP Code is:

 

 

CREATE PROCEDURE [dbo].[SPInsertIndividual]
(
       @IndividualID int OUTPUT,
	   @TypeName nvarchar(200),
	   @RankName nvarchar(200),
	   @TitleName nvarchar(200),
	   @FamilyName nvarchar(200),
	   @FirstName nvarchar(200),
	   @MiddleName1 nvarchar(200),
	   @MiddleName2 nvarchar(200),
	   @MiddleName3 nvarchar(200),
	   @Gender nvarchar(20),
	   @DOB nvarchar(200),
	   @CountryName nvarchar(200),
	   @StateName nvarchar(200),
	   @CityName nvarchar(200),
	   @Verification nvarchar(200),
	   @DateCreated DateTime
	   
)                  
AS 
BEGIN 
	 	 
	 SET NOCOUNT ON
 
     INSERT INTO dbo.tblIndividual(TypeName, RankName, TitleName, FamilyName, FirstName, MiddleName1, MiddleName2, MiddleName3, Gender, DOB, CountryName, StateName, CityName, Verification, DateCreated, IndividualID) 
     VALUES(@TypeName, @RankName, @TitleName, @FamilyName, @FirstName, @MiddleName1, @MiddleName2, @MiddleName3, @Gender, @DOB, @CountryName, @StateName, @CityName, @Verification, @DateCreated, @IndividualID)
	 
	 
END

Aspx.cs Code is

 

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            String strConnString = ConfigurationManager.ConnectionStrings["AspGenealogy"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
 
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "SPInsertIndividual";
 
            var id = new SqlParameter("IndividualID", System.Data.SqlDbType.Int);
            id.Direction = System.Data.ParameterDirection.Output;
            cmd.Parameters.Add(id);
 
            cmd.Parameters.Add("@IndividualID", SqlDbType.Int);
            
            cmd.Parameters.Add("@TypeName", SqlDbType.VarChar).Value = ddlType.SelectedItem.Text.Trim();
            
            cmd.Parameters.Add("@RankName", SqlDbType.VarChar).Value = ddlRank.SelectedItem.Text.Trim();
            
            cmd.Parameters.Add("@TitleName", SqlDbType.VarChar).Value = ddlTitle.SelectedItem.Text.Trim();
            cmd.Parameters.Add("@FamilyName", SqlDbType.VarChar).Value = txtFamilyName.Text.Trim();
            cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text.Trim();
            cmd.Parameters.Add("@MiddleName1", SqlDbType.VarChar).Value = txtMiddleName1.Text.Trim();
            cmd.Parameters.Add("@MiddleName2", SqlDbType.VarChar).Value = txtMiddleName2.Text.Trim();
            cmd.Parameters.Add("@MiddleName3", SqlDbType.VarChar).Value = txtMiddleName3.Text.Trim();
            cmd.Parameters.Add("@Gender", SqlDbType.VarChar).Value = ddlGender.SelectedItem.Text.Trim();
            cmd.Parameters.Add("@DOB", SqlDbType.VarChar).Value = txtDOB.Text.Trim();
            
            cmd.Parameters.Add("@CountryName", SqlDbType.VarChar).Value = ddlCountry.SelectedItem.Text.Trim();
            
            cmd.Parameters.Add("@StateName", SqlDbType.VarChar).Value = ddlState.SelectedItem.Text.Trim();
            
            cmd.Parameters.Add("@CityName", SqlDbType.VarChar).Value = ddlCity.SelectedItem.Text.Trim();
            cmd.Parameters.Add("@Verification", SqlDbType.VarChar).Value = txtVerification.Text.Trim();
            cmd.Parameters.Add("@DateCreated", SqlDbType.DateTime).Value = DateTime.Now;
            cmd.Connection = con;
 
            try
            {
 

                con.Open();
                cmd.ExecuteNonQuery();
                Response.Redirect("Details.aspx");
 
            }
 
            catch (Exception ex)
            {
                
                throw ex;
 
            }
 
            finally
            {
 
                con.Close();
                con.Dispose();
 
            }

My .aspx code is:

 

<body>
    <form id="form1" runat="server">
    <div style="font-family:Gabriola">
        <fieldset style="width:380px">
            <legend><h3>Individual Builder: Stage 1</h3></legend>
            <tr>
                <td>
                    Type:
                </td>
                <td>
                                                                                    
                    <asp:DropDownList ID="ddlType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlType_SelectedIndexChanged" DataTextField="TypeName" DataValueField="TypeID"></asp:DropDownList>
                
 
                </td>
            </tr>
            <tr>
                <td>
                    Rank:
                </td>
                <td>
                                                                                   
                    <asp:DropDownList ID="ddlRank" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlRank_SelectedIndexChanged" DataTextField="RankName" DataValueField="RankID"></asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    
 
                    Title:
                </td>
                <td>
                                                                                     
                    <asp:DropDownList ID="ddlTitle" AutoPostBack="true" runat="server" DataTextField="TitleName" DataValueField="TitleID"></asp:DropDownList>
                </td>
            </tr>
            ______________________________________________________________________________________________________________________________________________
            
 
            <tr>
                <td>
                Family Name:
            </td>
            <td>
                                                                
                <asp:TextBox ID="txtFamilyName" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
                <td>
                
 
                First Name:
            </td>
            <td>
                                                                   
                <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
                <td>
                Middle Name:
            </td>
            <td>
                                                               
                <asp:TextBox ID="txtMiddleName1" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
                <td>
                Middle Name:
                </td>
                
            <td>
                                                               
                <asp:TextBox ID="txtMiddleName2" runat="server"></asp:TextBox>
            </td>
                </tr>
            <tr>
                <td>
                Middle Name:
            </td>
            <td>
                                                               
                <asp:TextBox ID="txtMiddleName3" runat="server"></asp:TextBox>
            </td>
            </tr>
            
 
            ______________________________________________________________________________________________________________________________________________
            
 
            <tr>
        <td>
            Gender:
        </td>
        <td>
                                                                   
            <asp:DropDownList ID="ddlGender" runat="server">
                <asp:ListItem Value="0">Male</asp:ListItem>
                <asp:ListItem Value="1">Female</asp:ListItem>
            </asp:DropDownList>
            
        </td>
    </tr>
            <tr>
                <td>
                    
 
                    Date of Birth:
                </td>
                <td>
                                                                 
                    <asp:TextBox ID="txtDOB" runat="server"></asp:TextBox>
                </td>
            </tr>
            
 
            ______________________________________________________________________________________________________________________________________________
            <tr>
                <td>
                    Country of Birth:
                </td>
                <td>
                                                          
                    <asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" style="height: 22px" DataTextField="CountryName" DataValueField="CountryID"></asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    
 
                    Province or State of Birth:
                </td>
                <td>
                                           
                    <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlState_SelectedIndexChanged" DataTextField="StateName" DataValueField="StateID"></asp:DropDownList>
                
 
                </td>
            </tr>
            <tr>
                <td>
                    City of Birth:
                </td>
                <td>
                                                                 
                    <asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true" DataTextField="CityName" DataValueField="CityID"></asp:DropDownList>
                </td>
            </tr>
 
            
 
            ______________________________________________________________________________________________________________________________________________
            <tr>
                <td>
                    Source:
                </td>
                <td>
                                                                          
                    <asp:TextBox ID="txtVerification" runat="server"></asp:TextBox>
                </td>
            </tr>
            
 
            ______________________________________________________________________________________________________________________________________________
            <tr>
                <td>
                         
                    <asp:Button ID="btnClear" runat="server" Text="Clear" />
                </td>
                <td>
                                                                                                      
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
                </td>
            </tr>
        </fieldset>    
    </div>
    </form>
</body>

 

Can anyone help me? I am sure it is something minor.
 
Thanks, I look forward to hearing from you.

You are viewing reply posted by: Mudassar on Sep 19, 2014 02:50 AM.
Posted on Sep 19, 2014 02:50 AM

You are adding the Individual Parameter twice and hence remove

 cmd.Parameters.Add("@IndividualID", SqlDbType.Int);

 

I agree, here is the link: http://e-iceblue.com/free-api