| | |
Procedure or Function has too many arguments specified
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
Hey People 
A little quesion for you all ...
I have a stored procedure which retrieves an ID from a Customer table and the ID from the newly Inserted row of the Vehicle table and adds them to a new table.
On my form I have a dropDown where the user can select a Name. I then force my code to get the ID for that name using a stored procedure and have the result stored in an integer variable. So what I was aiming for in the following code was to be able to pass in the integer value in the C# code to the procedure along with the rest of the data and have it save to both tables respectively.
Initially I had the Commented Out code as part of the procedure and on execution of the procedure (and knowing and manually typing the unique ID value for the Customer) it added the data to both tables. However when I ran it from my code it told me it could not find the Procedure or Function named "AddNewVehicle" when it was blatently staring it in the face!!!
As it stands now with the code belowDoes anyone know or hazard a guess as to why I am getting the error "Procedure or Function CreateVehicle has too many arguments specified"
The C# syntax is as follows::
I know this is the long winded version, and someone nicely showed me a neater way of doing this. But once I get the basics of my program working I will spend time playing about with more elegant coding.
On counting the parameters above, there are 12 (there are 11 and 1 declared in the sproc)
Can anyone throw some suggestions my way please
Elmo

A little quesion for you all ...
I have a stored procedure which retrieves an ID from a Customer table and the ID from the newly Inserted row of the Vehicle table and adds them to a new table.
On my form I have a dropDown where the user can select a Name. I then force my code to get the ID for that name using a stored procedure and have the result stored in an integer variable. So what I was aiming for in the following code was to be able to pass in the integer value in the C# code to the procedure along with the rest of the data and have it save to both tables respectively.
Initially I had the Commented Out code as part of the procedure and on execution of the procedure (and knowing and manually typing the unique ID value for the Customer) it added the data to both tables. However when I ran it from my code it told me it could not find the Procedure or Function named "AddNewVehicle" when it was blatently staring it in the face!!!
As it stands now with the code belowDoes anyone know or hazard a guess as to why I am getting the error "Procedure or Function CreateVehicle has too many arguments specified"
C# Syntax (Toggle Plain Text)
ALTER PROCEDURE dbo.AddNewVehicle -- Declare variables for inserts into 2 tables ( @reg nvarchar(50), -- 1 @manufacturer nvarchar(50), -- 2 @model nvarchar (50), -- 3 @genericName nvarchar(50), -- 4 @fleetNo nvarchar(50), -- 5 @serialNo nvarchar(50), -- 6 @engineNo nvarchar(50), -- 7 @chassisNo nvarchar(50), -- 8 @vinNo nvarchar(50), -- 9 @year nvarchar(4), -- 10 @colour nvarchar(50) -- 11 --@idcompany int -- 12 (although declared again below) ) AS DECLARE @idvehicle int DECLARE @idcompany int -- newly added -- Insert all data into the Vehicle table INSERT INTO Vehicle(Registration, Manufacturer, Model, GenericName, FleetNo, SerialNo, EngineNo, ChassisNo, VIN_No, YearOfManufacture, Colour) VALUES (@reg, @manufacturer, @model, @genericName, @fleetNo, @serialNo, @engineNo, @chassisNo, @vinNo, @year, @colour) -- Retrieve the automatically generated ID value from the Vehicle table SET @idvehicle = @@IDENTITY /*SELECT ID_Company FROM Customer WHERE ID_Company = @idcompany */ -- Insert new value into the Customer_Vehicle table INSERT INTO Customer_Vehicle(ID_Company, ID_Vehicle) VALUES(@idcompany, @idvehicle) RETURN
The C# syntax is as follows::
C# Syntax (Toggle Plain Text)
public void setVehicleDetails() { getCompanyID(); //Declare myCommand properties //myCommand = new SqlCommand("AddNewVehicle", myConnection); myCommand = new SqlCommand("CreateVehicle", myConnection); myCommand.CommandType = CommandType.StoredProcedure; //Open connection to the database myConnection.Open(); //Initialise new instances of SqlParameter that declare the data type, size and column name //for the data that is being passed in. myCommand.Parameters.Add(new SqlParameter("@reg", SqlDbType.NVarChar, 50, "Registration")); myCommand.Parameters.Add(new SqlParameter("@manufacturer", SqlDbType.NVarChar, 50, "Manufacturer")); myCommand.Parameters.Add(new SqlParameter("@model", SqlDbType.NVarChar, 50, "Model")); myCommand.Parameters.Add(new SqlParameter("@genericName", SqlDbType.NVarChar, 50, "GenericName")); myCommand.Parameters.Add(new SqlParameter("@fleetNo", SqlDbType.NVarChar, 50, "FleetNo")); myCommand.Parameters.Add(new SqlParameter("@serialNo", SqlDbType.NVarChar, 50, "SerialNo")); myCommand.Parameters.Add(new SqlParameter("@engineNo", SqlDbType.NVarChar, 50, "EngineNo")); myCommand.Parameters.Add(new SqlParameter("@chassisNo", SqlDbType.NVarChar, 50, "ChassisNo")); myCommand.Parameters.Add(new SqlParameter("@vinNo", SqlDbType.NVarChar, 50, "VIN_No")); myCommand.Parameters.Add(new SqlParameter("@year", SqlDbType.NVarChar, 4, "YearOfManufacture")); myCommand.Parameters.Add(new SqlParameter("@colour", SqlDbType.NVarChar, 50, "Colour")); myCommand.Parameters.Add(new SqlParameter("@idcompany",i_companyID));//, SqlDbType.Int, 4, "ID_Company")); //Adds data to the Vehicle and Customer_Vehicle table based on the parameters passed in. myCommand.Parameters["@reg"].Value = txt_Ex_Registration.Text; myCommand.Parameters["@manufacturer"].Value = txt_Ex_Manufacturer.Text; myCommand.Parameters["@model"].Value = txt_Ex_Model.Text; myCommand.Parameters["@genericName"].Value = txt_Ex_GenericName.Text; myCommand.Parameters["@fleetNo"].Value = txt_Ex_FleetNo.Text; myCommand.Parameters["@serialNo"].Value = txt_Ex_SerialNo.Text; myCommand.Parameters["@engineNo"].Value = txt_Ex_EngineNo.Text; myCommand.Parameters["@chassisNo"].Value = txt_Ex_ChassisNo.Text; myCommand.Parameters["@vinNo"].Value = txt_Ex_VinNo.Text; myCommand.Parameters["@year"].Value = txt_Ex_Year.Text; myCommand.Parameters["@colour"].Value = txt_Ex_Colour.Text; //myCommand.Parameters["@idcompany"].Value = i_companyID; //Close and dispose of open properties myCommand.ExecuteNonQuery(); myCommand.Dispose(); myConnection.Close(); }
I know this is the long winded version, and someone nicely showed me a neater way of doing this. But once I get the basics of my program working I will spend time playing about with more elegant coding.
On counting the parameters above, there are 12 (there are 11 and 1 declared in the sproc)
Can anyone throw some suggestions my way please

Elmo
Michelle (Junior Developer)
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 137
You are still adding the companyid parameter.
Take that out and you should be good to go.
Take that out and you should be good to go.
C# Syntax (Toggle Plain Text)
myCommand.Parameters.Add(new SqlParameter("@idcompany",i_companyID));//, SqlDbType.Int, 4, "ID_Company"));
The Green highlighted pieces show the code that I had that successfully added the data to the tables but I had to manually enter the ID number ... the code then selected the ID_Company based on that parameter and added to the table new table (all this worked with the Executing the stored procedure and viewing the output in the output window BUT would not recognise that the sproc existed in my code)
I hope this makes sense!
The red pieces of code show the changes that I made to the sproc. I declared the @idcompany inside the sproc with the hope that I could pass in an integer variable declared in my code which stores the ID for ID_Company after the user selects the Company Name from a drop down list.
I hope this makes sense!
The red pieces of code show the changes that I made to the sproc. I declared the @idcompany inside the sproc with the hope that I could pass in an integer variable declared in my code which stores the ID for ID_Company after the user selects the Company Name from a drop down list.
•
•
•
•
ALTER PROCEDURE dbo.AddNewVehicle -- Declare variables for inserts into 2 tables ( @reg nvarchar(50), -- 1 @manufacturer nvarchar(50), -- 2 @model nvarchar (50), -- 3 @genericName nvarchar(50), -- 4 @fleetNo nvarchar(50), -- 5 @serialNo nvarchar(50), -- 6 @engineNo nvarchar(50), -- 7 @chassisNo nvarchar(50), -- 8 @vinNo nvarchar(50), -- 9 @year nvarchar(4), -- 10 @colour nvarchar(50) -- 11 --@idcompany int -- 12 (although declared again below) ) AS DECLARE @idvehicle int DECLARE @idcompany int -- newly added -- Insert all data into the Vehicle table INSERT INTO Vehicle(Registration, Manufacturer, Model, GenericName, FleetNo, SerialNo, EngineNo, ChassisNo, VIN_No, YearOfManufacture, Colour) VALUES (@reg, @manufacturer, @model, @genericName, @fleetNo, @serialNo, @engineNo, @chassisNo, @vinNo, @year, @colour) -- Retrieve the automatically generated ID value from the Vehicle table SET @idvehicle = @@IDENTITY /*SELECT ID_Company FROM Customer WHERE ID_Company = @idcompany */ -- Insert new value into the Customer_Vehicle table INSERT INTO Customer_Vehicle(ID_Company, ID_Vehicle) VALUES(@idcompany, @idvehicle) RETURN
The C# syntax is as follows::
ElmomyCommand.Parameters.Add(new SqlParameter("@idcompany",i_companyID)); // The above line SHOULD take in the unique ID value and pass into the sproc }
Last edited by Elmo_loves_you; Aug 22nd, 2008 at 10:25 am. Reason: tweaked the C# code at bottom
Michelle (Junior Developer)
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 137
I'm not understanding that if you already have the company_id, why you don't want to pass it in.
You are inserting the new vehicle, and have a company id already.
I would suggest creating two stored procedures. Maintain this one that inserts a vehicle only and another stored procedure that calls to insert the vehicle, gets the id, and makes the call to insert customer vehicle.
You are inserting the new vehicle, and have a company id already.
I would suggest creating two stored procedures. Maintain this one that inserts a vehicle only and another stored procedure that calls to insert the vehicle, gets the id, and makes the call to insert customer vehicle.
I have two different versions of the AddNewVehicle sproc (purely because the program threw a hissy fit by saying it couldnt see the CreateVehicle sproc)
the content of both are the same as defined above.
I have 3 tables (Customer, Vehicle and Customer_Vehicle)
The idea is that somebody could phone in and request information about some product a company sells...the company could record their details on the system...then if that customer decides they would like to buy a product, then the company would be able to search the Existing customers (dropDown list) and then proceed to type in relevant information ... then click on an "ADD" button
this button would then trigger a method that adds the text enetered into textboxex on the interface along with the value stored in the integer variable (referring to the name the user chose from the dropdown list)
So, the integer variable and all the textbox.text values are all passed into their respective parameters of the sproc .... then there should be a successful entry (but theres not)
the content of both are the same as defined above.
I have 3 tables (Customer, Vehicle and Customer_Vehicle)
The idea is that somebody could phone in and request information about some product a company sells...the company could record their details on the system...then if that customer decides they would like to buy a product, then the company would be able to search the Existing customers (dropDown list) and then proceed to type in relevant information ... then click on an "ADD" button
this button would then trigger a method that adds the text enetered into textboxex on the interface along with the value stored in the integer variable (referring to the name the user chose from the dropdown list)
So, the integer variable and all the textbox.text values are all passed into their respective parameters of the sproc .... then there should be a successful entry (but theres not)
Michelle (Junior Developer)
•
•
•
•
I'm not understanding that if you already have the company_id, why you don't want to pass it in.
You are inserting the new vehicle, and have a company id already.
I would suggest creating two stored procedures. Maintain this one that inserts a vehicle only and another stored procedure that calls to insert the vehicle, gets the id, and makes the call to insert customer vehicle.

but either way I will still be faced with the problem of inserting the ID value for the Customer name selected from the DropDown list.
How can I write a stored procedure that accepts a variable from the code?
Im confusing myself now with this lol
Michelle (Junior Developer)
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 137
lol what?
I thought you already have the stored procedure in the database, and you are accepting the values through the code.
You mean the above code is not hitting the database?
I thought you already have the stored procedure in the database, and you are accepting the values through the code.
C# Syntax (Toggle Plain Text)
myCommand = new SqlCommand("CreateVehicle", myConnection); myCommand.CommandType = CommandType.StoredProcedure;
You mean the above code is not hitting the database?
•
•
•
•
lol what?
I thought you already have the stored procedure in the database, and you are accepting the values through the code.
C# Syntax (Toggle Plain Text)
myCommand = new SqlCommand("CreateVehicle", myConnection); myCommand.CommandType = CommandType.StoredProcedure;
You mean the above code is not hitting the database?
yes - but ...

when I test the stored procedure itself...it DOES add to the database...
but when I run the code its throwing a fit!!
Michelle (Junior Developer)
![]() |
Similar Threads
- Procedure or function has too many arguments specified. (ASP.NET)
- C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays (C++)
Other Threads in the C# Forum
- Previous Thread: To run exe on client machine from a webpage
- Next Thread: Mapping Rows between two datagridviews
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






