[Solved] Procedure or function xxx has too many arguments specified – ASP.NET

If you are getting this error in your .NET application (AsP.NET for example), it says obvious that you are passing too many parameters to the stored Procedure. However there is a scenario where this error actually makes you look in the wrong direction. Example is below

you have sqldataSource which inserts a customer into the database for example. Let say a customer is renewed and you want to store the ID of the old customer in a field “OLDID”. Now your stored procedure looks like this

InsertCustomer(
@ID int,
@name varchar(25),


@OldID int
)

In ASP.NET When you bind a value to the @OldID parameter, according to the logic you should be actually doing this

<asp/textbox id="txtOldID" text= Text='’

Note that I am updating txtOLDID field through backend programming in C# in page_load function. Now everything looks according to the book. You need to pass @oldID to the stored procedure, there is a field @oldID and you are binding your textbox to that field. But it does not work and instead throughs this exception.

In this case the error is misleading, the fix is rather change the stored procedure.

How to fix this?

Change the stored procedure so that @OldID parameter reads as @ID. Down in the store procedure, use the correct logic where there this ID needs to be inserted. Since we want to use it in place of OLDID, the logic should be follow

insert into customer (OLDID) values(ID)

Now in the ASP.NET application, change the binding to ID field rather than OLDID and everything should work fine. It is rather bizarre error.

this will give you the following error. Everything is according to the book.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to [Solved] Procedure or function xxx has too many arguments specified – ASP.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s