Procedure or Function has too many arguments specified

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Procedure or Function has too many arguments specified

 
0
  #1
Aug 22nd, 2008
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"

  1. ALTER PROCEDURE dbo.AddNewVehicle
  2. -- Declare variables for inserts into 2 tables
  3. (
  4. @reg nvarchar(50), -- 1
  5. @manufacturer nvarchar(50), -- 2
  6. @model nvarchar (50), -- 3
  7. @genericName nvarchar(50), -- 4
  8. @fleetNo nvarchar(50), -- 5
  9. @serialNo nvarchar(50), -- 6
  10. @engineNo nvarchar(50), -- 7
  11. @chassisNo nvarchar(50), -- 8
  12. @vinNo nvarchar(50), -- 9
  13. @year nvarchar(4), -- 10
  14. @colour nvarchar(50) -- 11
  15. --@idcompany int -- 12 (although declared again below)
  16. )
  17.  
  18. AS
  19. DECLARE @idvehicle int
  20. DECLARE @idcompany int -- newly added
  21.  
  22. -- Insert all data into the Vehicle table
  23. INSERT INTO Vehicle(Registration, Manufacturer, Model, GenericName, FleetNo, SerialNo, EngineNo, ChassisNo, VIN_No, YearOfManufacture, Colour)
  24. VALUES (@reg, @manufacturer, @model, @genericName, @fleetNo, @serialNo, @engineNo, @chassisNo, @vinNo, @year, @colour)
  25.  
  26. -- Retrieve the automatically generated ID value from the Vehicle table
  27. SET @idvehicle = @@IDENTITY
  28.  
  29. /*SELECT ID_Company
  30. FROM Customer
  31. WHERE ID_Company = @idcompany
  32. */
  33. -- Insert new value into the Customer_Vehicle table
  34. INSERT INTO Customer_Vehicle(ID_Company, ID_Vehicle)
  35. VALUES(@idcompany, @idvehicle)
  36.  
  37. RETURN

The C# syntax is as follows::

  1.  
  2. public void setVehicleDetails()
  3. {
  4. getCompanyID();
  5. //Declare myCommand properties
  6. //myCommand = new SqlCommand("AddNewVehicle", myConnection);
  7. myCommand = new SqlCommand("CreateVehicle", myConnection);
  8. myCommand.CommandType = CommandType.StoredProcedure;
  9.  
  10. //Open connection to the database
  11. myConnection.Open();
  12.  
  13. //Initialise new instances of SqlParameter that declare the data type, size and column name
  14. //for the data that is being passed in.
  15. myCommand.Parameters.Add(new SqlParameter("@reg", SqlDbType.NVarChar, 50, "Registration"));
  16. myCommand.Parameters.Add(new SqlParameter("@manufacturer", SqlDbType.NVarChar, 50, "Manufacturer"));
  17. myCommand.Parameters.Add(new SqlParameter("@model", SqlDbType.NVarChar, 50, "Model"));
  18. myCommand.Parameters.Add(new SqlParameter("@genericName", SqlDbType.NVarChar, 50, "GenericName"));
  19. myCommand.Parameters.Add(new SqlParameter("@fleetNo", SqlDbType.NVarChar, 50, "FleetNo"));
  20. myCommand.Parameters.Add(new SqlParameter("@serialNo", SqlDbType.NVarChar, 50, "SerialNo"));
  21. myCommand.Parameters.Add(new SqlParameter("@engineNo", SqlDbType.NVarChar, 50, "EngineNo"));
  22. myCommand.Parameters.Add(new SqlParameter("@chassisNo", SqlDbType.NVarChar, 50, "ChassisNo"));
  23. myCommand.Parameters.Add(new SqlParameter("@vinNo", SqlDbType.NVarChar, 50, "VIN_No"));
  24. myCommand.Parameters.Add(new SqlParameter("@year", SqlDbType.NVarChar, 4, "YearOfManufacture"));
  25. myCommand.Parameters.Add(new SqlParameter("@colour", SqlDbType.NVarChar, 50, "Colour"));
  26. myCommand.Parameters.Add(new SqlParameter("@idcompany",i_companyID));//, SqlDbType.Int, 4, "ID_Company"));
  27.  
  28. //Adds data to the Vehicle and Customer_Vehicle table based on the parameters passed in.
  29. myCommand.Parameters["@reg"].Value = txt_Ex_Registration.Text;
  30. myCommand.Parameters["@manufacturer"].Value = txt_Ex_Manufacturer.Text;
  31. myCommand.Parameters["@model"].Value = txt_Ex_Model.Text;
  32. myCommand.Parameters["@genericName"].Value = txt_Ex_GenericName.Text;
  33. myCommand.Parameters["@fleetNo"].Value = txt_Ex_FleetNo.Text;
  34. myCommand.Parameters["@serialNo"].Value = txt_Ex_SerialNo.Text;
  35. myCommand.Parameters["@engineNo"].Value = txt_Ex_EngineNo.Text;
  36. myCommand.Parameters["@chassisNo"].Value = txt_Ex_ChassisNo.Text;
  37. myCommand.Parameters["@vinNo"].Value = txt_Ex_VinNo.Text;
  38. myCommand.Parameters["@year"].Value = txt_Ex_Year.Text;
  39. myCommand.Parameters["@colour"].Value = txt_Ex_Colour.Text;
  40. //myCommand.Parameters["@idcompany"].Value = i_companyID;
  41.  
  42. //Close and dispose of open properties
  43. myCommand.ExecuteNonQuery();
  44.  
  45. myCommand.Dispose();
  46. myConnection.Close();
  47. }

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)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Procedure or Function has too many arguments specified

 
0
  #2
Aug 22nd, 2008
You are still adding the companyid parameter.
Take that out and you should be good to go.
  1. myCommand.Parameters.Add(new SqlParameter("@idcompany",i_companyID));//, SqlDbType.Int, 4, "ID_Company"));
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Re: Procedure or Function has too many arguments specified

 
0
  #3
Aug 22nd, 2008
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.

Originally Posted by Elmo_loves_you View Post

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::


             myCommand.Parameters.Add(new SqlParameter("@idcompany",i_companyID));

             // The above line SHOULD take in the unique ID value and pass into the sproc
            
        }
Elmo
Last edited by Elmo_loves_you; Aug 22nd, 2008 at 10:25 am. Reason: tweaked the C# code at bottom
Michelle (Junior Developer)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Procedure or Function has too many arguments specified

 
0
  #4
Aug 22nd, 2008
What is the create vehicle stored proc?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Procedure or Function has too many arguments specified

 
0
  #5
Aug 22nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Re: Procedure or Function has too many arguments specified

 
0
  #6
Aug 22nd, 2008
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)
Michelle (Junior Developer)
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Re: Procedure or Function has too many arguments specified

 
0
  #7
Aug 22nd, 2008
Originally Posted by dickersonka View Post
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.
Thats a valid point

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)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Procedure or Function has too many arguments specified

 
0
  #8
Aug 22nd, 2008
lol what?

I thought you already have the stored procedure in the database, and you are accepting the values through the code.

  1. myCommand = new SqlCommand("CreateVehicle", myConnection);
  2. myCommand.CommandType = CommandType.StoredProcedure;

You mean the above code is not hitting the database?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Re: Procedure or Function has too many arguments specified

 
0
  #9
Aug 22nd, 2008
Originally Posted by dickersonka View Post
lol what?

I thought you already have the stored procedure in the database, and you are accepting the values through the code.

  1. myCommand = new SqlCommand("CreateVehicle", myConnection);
  2. myCommand.CommandType = CommandType.StoredProcedure;

You mean the above code is not hitting the database?
lol

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)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Procedure or Function has too many arguments specified

 
0
  #10
Aug 22nd, 2008
The code needs to call the stored procedure we have...I believe lol.

What happens when you do this?

myCommand = new SqlCommand("AddNewVehicle", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC