How to resolve Procedure or function has too many arguments specified in .NET

Posted By  RRaveen On 02 Aug 2010 01:08:48
emailbookmarkadd commentsprint
No of Views:2326
Bookmarked:0 times
Votes:0 times

Introduction

This 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 Overview

How 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.

Implementation

Case 01-With NULL parameter

CREATE 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 parameter

CREATE 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.

Conclusion

In this tips, I have given cases to resolve the above error when you are call stored procedures in your application. Enjoy bug free programming.

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top