C# 过程或函数指定了太多参数 #2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10891693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Procedure or function has too many arguments specified #2
提问by Aravind Sai
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.""
嗨,我试图将数据插入数据库,利用类文件..我有两个类,其中一个是 Material.cs 和 DataAccessLayer.cs。但是执行我的代码时出现错误,例如程序或函数 sp_insert_componet 指定了太多参数。""
//From Material.cs
//来自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
//来自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();
}
}
采纳答案by TGH
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
在存储过程中有相应的参数。删除过程中未定义的任何参数
回答by Raab
the Problem is that you have less input parameter defined in your Stored Procedure sp_insert_componet.
问题是您在存储过程中定义的输入参数较少sp_insert_componet。
Compare the Number of parameters in your C# code to the ones in your stored procedure.
将 C# 代码中的参数数量与存储过程中的参数数量进行比较。
回答by Omer Asif
if the number of parameters are same then try to check their types.
如果参数数量相同,则尝试检查它们的类型。
parameter types must be the same as in the table
参数类型必须与表中相同
回答by Richard
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.
我遇到这个问题是因为我的配置文件指向错误的数据库,该数据库具有相同的 SP 和不同的参数。

