Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Error:
The formal parameter "@SupplierID" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output.


Stored Proc:
SQL
GO
CREATE PROCEDURE ViewMaintenance
	@FormID nchar(5),
	@SupplierID nchar(5),
	@PlateNumber nchar(6),
	@ServiceForm xml
AS
	SET NOCOUNT ON;
	
	Select FormID, SupplierID, PlateNumber, ServiceForm
	From Maintenance
	Where FormID = @FormID AND SupplierID = @SupplierID
	AND PlateNumber = @PlateNumber AND ServiceForm IS NULL
GO

Code Behind:
C#
SqlConnection conn = new SqlConnection("Data Source=JOSE-PC;Initial Catalog=AKDB;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("ViewMaintenance",conn);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter formid_param = cmd.Parameters.Add("@FormID", SqlDbType.Int);
            SqlParameter supplierid_param = cmd.Parameters.Add("@SupplierID", SqlDbType.NChar,5);
            SqlParameter platenumber_param = cmd.Parameters.Add("@PlateNumber", SqlDbType.NChar,6);

            formid_param.Direction = ParameterDirection.Input;
            supplierid_param.Direction = ParameterDirection.Output;
            platenumber_param.Direction = ParameterDirection.Output;

            formid_param.Value = Convert.ToInt32(txtFormNo.Text);

            if(conn.State.Equals(ConnectionState.Closed))
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                
            }
            txtFormNo.Text = formid_param.ToString();
            txtRequestedTo.Text = supplierid_param.ToString();
            txtVehicle.Text = platenumber_param.ToString();

            conn.Close();

Hoping the solve this problem:(
Posted
Updated 12-Jun-12 23:55pm
v2
Comments
RDBurmon 13-Jun-12 9:24am    
Thanks Everyone who replied to this thread , So EvanJo, I think you have got enough responses and you should be able to mark it as your answer and close the thread. Please do so.

SQL
GO CREATE PROCEDURE ViewMaintenance 
@FormID nchar(5), 
@SupplierID nchar(5), 
@PlateNumber nchar(6)
 AS SET NOCOUNT ON;
 Select FormID, SupplierID,
 PlateNumber, ServiceForm From Maintenance Where FormID = @FormID AND SupplierID = @SupplierID AND 
PlateNumber = @PlateNumber AND ServiceForm IS NULL GO


And in code


C#
SqlConnection conn = new SqlConnection("Data Source=JOSE-PC;Initial Catalog=AKDB;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("ViewMaintenance",conn);
            cmd.CommandType = CommandType.StoredProcedure;
 
            SqlParameter formid_param = cmd.Parameters.Add("@FormID", SqlDbType.Int);
            SqlParameter supplierid_param = cmd.Parameters.Add("@SupplierID", SqlDbType.NChar,5);
            SqlParameter platenumber_param = cmd.Parameters.Add("@PlateNumber", SqlDbType.NChar,6);
 
            formid_param.Direction = ParameterDirection.Input;
            supplierid_param.Direction = ParameterDirection.Input;
            platenumber_param.Direction = ParameterDirection.Input;
 
            formid_param.Value = Convert.ToInt32(txtFormNo.Text);
 
            if(conn.State.Equals(ConnectionState.Closed))
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                
            }
            txtFormNo.Text = formid_param.ToString();
            txtRequestedTo.Text = supplierid_param.ToString();
            txtVehicle.Text = platenumber_param.ToString();
 
            conn.Close();
 
Share this answer
 
v2
please change the code as follows...

C#
supplierid_param.Direction = ParameterDirection.Input;
platenumber_param.Direction = ParameterDirection.Input;


this might solve your issue.

Regards
Sebastian
 
Share this answer
 
Please remove the lines,
C#
formid_param.Direction = ParameterDirection.Input;
supplierid_param.Direction = ParameterDirection.Output;
platenumber_param.Direction = ParameterDirection.Output;


Since ParameterDirection is an optional one.The default is Input.

If you want the get output from SP then use ParameterDirection.Output in C# and declaration in SP like

....
SQL
@SupplierID nchar(5) output,
@PlateNumber nchar(6) output,

....
 
Share this answer
 
v2
Comments
EvanJo 13-Jun-12 6:09am    
I already update my SP as you said, but I have another error

It says like this : Procedure or function 'ViewMaintenance' expects parameter '@ServiceForm', which was not supplied.
Tony Tom.k 13-Jun-12 7:39am    
Remove that @ServiceForm your sps declaration part Your not Passing any value then why you are declared it as input parameter
Tony Tom.k 13-Jun-12 7:39am    
GOCREATE PROCEDURE ViewMaintenance
@FormID nchar(5),
@SupplierID nchar(5),
@PlateNumber nchar(6)
AS
SET NOCOUNT ON;

Select FormID, SupplierID, PlateNumber, ServiceForm
From Maintenance
Where FormID = @FormID AND SupplierID = @SupplierID
AND PlateNumber = @PlateNumber AND ServiceForm IS NULL
GO
Hi,
As your stored procedure says that
SQL
@SupplierID
and
SQL
@PlateNumber
is not output parameter and you still want to use it as output parameter.. Definitely it will give an error.. It can only take the data from front-end but it will not return any data from back-end to front-end.

You need to view this article:
Stored Procedure Data Gateway[^]
Sql Server - How to write a Stored procedure in Sql server[^]

All the best.
--AK
 
Share this answer
 
Chage SP like this


SQL
CREATE PROCEDURE ViewMaintenance
	@FormID nchar(5),
	@SupplierID nchar(5) output,
	@PlateNumber nchar(6) output,
	@ServiceForm xml
AS
	SET NOCOUNT ON;
	
	Select FormID, SupplierID, PlateNumber, ServiceForm
	From Maintenance
	Where FormID = @FormID AND SupplierID = @SupplierID
	AND PlateNumber = @PlateNumber AND ServiceForm IS NULL
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900