IntroductionThis is error is occurred when a developer or database administrator made mistake in stored procedures arguments count passing miss match. These types of errors, we can trouble shoot easily. By the error message itself, you able to understand “...too many arguments …”.means your stored procedures has less than or great than no of parameters count when you are passing arguments to procedure from your code. Solution OverviewHow we could solve? We don’t need write any code, but you have to stored procedures manually how many parameters could accept and which are mandatory and which are NOT mandatory. What you mean by the mandatory? If you are set NULL for parameters as default in stored procedure, then we can those parameters not mandatory, so you may ignore that to count. It mean you only count which are you not set NULL for the parameters. Because if you are set NULL, then database will sent NULL as default value for that parameter as argument. ImplementationCase 01-With NULL parameterCREATE PROCEDURE [dbo].[P_Course_Insert]@CourseID int,@CourseCode varchar(20),@CourseTitle nvarchar(100),@CourseShortTitle nvarchar(50) =NULLASINSERT INTO [dbo].[T_Course] ([CourseID],[CourseCode],[CourseTitle],[CourseShortTitle]) VALUES (@CourseID,@CourseCode,@CourseTitle,@CourseShortTitle) When you are call above procedure in your code, you have to sent CourseID,CourseCode and CourseTitle. CourseShortTitle is optional (default value is NULL), so you may / may not send too. So in this case you have to send three arguments when we are call this procedure in the .NET. When you are missed one out of three you will get above error. Case 02-Without NULL parameterCREATE PROCEDURE [dbo].[P_Course_Insert]@CourseID int,@CourseCode varchar(20),@CourseTitle nvarchar(100),@CourseShortTitle nvarchar(50)ASINSERT INTO [dbo].[T_Course] ([CourseID],[CourseCode],[CourseTitle],[CourseShortTitle]) VALUES (@CourseID,@CourseCode,@CourseTitle,@CourseShortTitle) When you are call above procedure in your code, you MUST have to sent CourseID,CourseCode , CourseTitle and CourseShortTitle. So in this case you have to send four arguments when we are call this procedure in the .NET. When you are missed one out of four you will get above error. ConclusionIn this tips, I have given cases to resolve the above error when you are call stored procedures in your application. Enjoy bug free programming. |