Procedure or function has too many arguments specified

后端 未结 2 1189
时光取名叫无心
时光取名叫无心 2021-01-18 03:05

I get an error

Procedure or function \"myStoreProcNameHere\" has too many arguments specified.

Below is my stored procedure and

相关标签:
2条回答
  • 2021-01-18 03:52

    Must of instance Create

    Vb.Net & C#

    glopal value

    vb.net -> Dim cmd as New SqlCommand()
    
    c#-> Sqlcommand cmd=new sqlCommand()
    
    Con.open()
    
    cmd=New SqlCommand()
    
    something write...
    
    Con.Close()
    
    0 讨论(0)
  • 2021-01-18 04:02

    I've ran into this error message before when I was calling a stored procedure from within a loop (foreach).

    The cause of the exception that I received was due to the fact that I wasn't clearing the Parameter's after each iteration of the loop.

    For example: This code throws:

    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.CommandText = "MySproc";
        foreach (MyClass c in myClasses)
        {
            cmd.Parameters.AddWithValue("@val1", c.val1);
            cmd.Parameters.AddWithValue("@val2", c.val2);
            var result = MyDbManager.instance.ExecuteScalarQuery(cmd);
        }
    }
    

    The fix was to clear the parameters:

    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.CommandText = "MySproc";
        foreach (MyClass c in myClasses)
        {
            cmd.Parameters.AddWithValue("@val1", c.val1);
            cmd.Parameters.AddWithValue("@val2", c.val2);
            var result = MyDbManager.instance.ExecuteScalarQuery(cmd);
            cmd.Parameters.Clear();
        }
    }
    
    0 讨论(0)
提交回复
热议问题