简体   繁体   中英

Procedure or function has too many arguments specified #2

hi i have tried to insert the data to data base, make use of class files.. I have two classes, from that one is Material.cs, and DataAccessLayer.cs. But executing my code i got error like Procedure or function sp_insert_componet has too many arguments specified.""

//From Material.cs

private string strCREATEDBY;
private string strCREATEDDATE;
private string strUPDATEDBY;
private string strUPDATEDDATE;
private string strSTATUS;

public string Createdby
{
    get
    {
        return strCREATEDBY;
    }
    set
    {
        strCREATEDBY = value;
    }
}
public string Createddate
{
    get
    {
        return strCREATEDDATE;
    }
    set
    {
        strCREATEDDATE = value;
    }
}
public string Updateddate
{
    get
    {
        return strUPDATEDDATE;
    }
    set
    {
        strUPDATEDDATE = value;
    }
}
public string Updatedby
{
    get
    {
        return strUPDATEDBY;
    }
    set
    {
        strUPDATEDBY = value;
    }
}
public string Status
{
    get
    {
        return strSTATUS;
    }
    set
    {
        strSTATUS = value;
    }
}

//Maingroup
//created by : ramya
//created date:15.2.2012
private string strIDENTIFY;
private string strNO;
private string strNAME;
private string strMAINIDENTIFICATION;


public string Identification
{
    get
    {
        return strIDENTIFY;
    }
    set
    {
        strIDENTIFY = value;
    }
}
public string NO
{
    get
    {
        return strNO;
    }
    set
    {
        strNO = value;
    }
}
public string NAME
{
    get
    {
        return strNAME;
    }
    set
    {
        strNAME = value;
    }
}
public string Mainidentify
{
    get
    {
        return strMAINIDENTIFICATION;
    }
    set
    {
        strMAINIDENTIFICATION = value;
    }
}
private string strItemtype;
public string Itemtype
{
    get
    {
        return strItemtype;
    }
    set
    {
        strItemtype = value;
    }
}
private string strSitename;
public string Sitename
{
    get
    {
        return strSitename;
    }
    set
    {
        strSitename = value;
    }
}

public int Savecomponent()
{
    objDL.Addparam("@Createdby", Createdby);
    objDL.Addparam("@Createddate", Createddate);
    objDL.Addparam("@Sitecode", NO);
    objDL.Addparam("@Itemtype", Itemtype);
    objDL.Addparam("@Status", Status);
    objDL.Addparam("@Maingroupsno", Mainidentify);
    objDL.Addparam("@Subgroupsno", Identification);
    objDL.Addparam("@Componetcode",NAME);
    objDL.Addparam("@Sitename", Sitename);
    int save = objDL.insert("sp_insert_componet");
    if (save > 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

//From DataAccessLayer.cs

public int insert(string strInsert)
{
    try
    {
        Con.Open();
        cmd.Connection = Con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = strInsert;
        int RetInsert = cmd.ExecuteNonQuery();
        return RetInsert;
    }
    catch (Exception ex)
    {
        throw ex;
    }
    //got error in this finally block

    finally
    {
        Con.Close();
    }
}

You are specifying arguments that the stored procedure isn't expecting. Remove any arguments that aren't defined by the stored procedure

Make sure that every parameter in the block

objDL.Addparam("@Createdby", Createdby);
objDL.Addparam("@Createddate", Createddate);
objDL.Addparam("@Sitecode", NO);
objDL.Addparam("@Itemtype", Itemtype);
objDL.Addparam("@Status", Status);
objDL.Addparam("@Maingroupsno", Mainidentify);
objDL.Addparam("@Subgroupsno", Identification);
objDL.Addparam("@Componetcode",NAME);
objDL.Addparam("@Sitename", Sitename);

has a corresponding parameter in the stored procedure. Remove any parameter that isn't defined in the procedure

if the number of parameters are same then try to check their types.

parameter types must be the same as in the table

Check your DB connections if using different DB environments.

I encountered this problem because my config file was pointing at the wrong database which had a the same SP with different parameters.

the Problem is that you have less input parameter defined in your Stored Procedure sp_insert_componet .

Compare the Number of parameters in your C# code to the ones in your stored procedure.

No, you'll get this error even when the parameters are exactly the same, in the case of a SQL INSERT in your stored procedure on SQL Server.

Turns out you have to ALSO define a parameter in the stored procedure for the PRIMARY KEY of the table in which you are inserting the new record into. In my case, @CompanyID NOT passed as a parameter, but without defining it, the "too many arguments" error occurs. If it helps to know, the CompanyID field has "identity" setting of "true", it gets incremented with every new record.

ALTER PROCEDURE [dbo].[FormViewCompanies_Insert](

@CompanyID AS INT. /* Not passed as a parameter */

@MemberID AS INT, /* Passed as a parameter / @ChapterID AS INT, / Passed as a parameter */ ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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