ADO/ADO.NET - SQL Procedures - Asked By Arunkumar on 03-Jan-11 05:04 AM

How does call the stored procedure to insert records continuously in one form load event and same button click events. if i do this first time the record is inserted successfully but i tried for the second  record it showed the prompt as "Stored procedure has too many arguments specified"... can any one of you give solution to this query...
                            Thank you All....
Danasegarane Arunachalam replied to Arunkumar on 03-Jan-11 05:24 AM
Stored procedure has too many arguments specified

This error means that you sp expects few parameters and you are not supplying any few of them

For eg.

You have sp called updatedb which accepts ID and Datetime . And you suppy ID and missed the Datetime
will result in this error
Reena Jain replied to Arunkumar on 03-Jan-11 05:27 AM

It happens when it is in a procedure is in  loop if you are running this code block in a for loop against some array of values.
In that case, you would need to add the parameters collection to the command object only once and before specifying the values for the parameters.

This should be the right way.

SqlParameter myParam = new SqlParameter("@username",SqlDbType.VarChar);

foreach(string user in userNames)
  myParam.Value = user;

hope this will help you
Venkat K replied to Arunkumar on 03-Jan-11 05:56 AM
The best way is to Copy the Insert query that produced through your application in debug mode and try to execute this in your SSMS (Sql server management studio) so that you will correct your insert query. YOu can also paste the query here to find the issue.

Clear the parameters after performing insertion into the table - Lalitha Kumaran replied to Arunkumar on 03-Jan-11 06:40 AM

Follow the below steps to avoid the runtime error

1. Clear the Parameters
2. pass the Parameter to the stored procedure
3. Call the stored Procedure