Hi everybody
I am a beginner and facing the problem in calling a Stored Procedure from within my VB.NET 2005, as below:
MY Stored Procedure goes like;
ALTER PROCEDURE ByRoyalty @percentage int, @avgprice float Output
AS
SELECT @avgprice= AVG(price) FROM titles
SELECT au_id FROM titleauthor
WHERE titleauthor.royaltyper = @percentage
DECLARE @numtitles Int
SELECT @numtitles=COUNT(*) FROM titles
RETURN @numtitles
My VB code is as below:
Dim cmd As New SqlCommand("ByRoyalty", Conxn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@numtitles", SqlDbType.Int)
.Parameters(0).Direction = ParameterDirection.ReturnValue
.Parameters.AddWithValue("@percentage", 100)
.Parameters(1).Direction = ParameterDirection.Input
.Parameters.Add("@avgprice", SqlDbType.Float)
.Parameters(2).Direction = ParameterDirection.Output
End With
Dim dr As SqlDataReader = cmd.ExecuteReader()
Running the above vb code reports the following error:
"Procedure or function ByRoyalty has too many arguments specified."
Please note that there are 2 parameters in the declaration, whereas third argument is declared inside the SP as;
Please help
I am a beginner and facing the problem in calling a Stored Procedure from within my VB.NET 2005, as below:
MY Stored Procedure goes like;
ALTER PROCEDURE ByRoyalty @percentage int, @avgprice float Output
AS
SELECT @avgprice= AVG(price) FROM titles
SELECT au_id FROM titleauthor
WHERE titleauthor.royaltyper = @percentage
DECLARE @numtitles Int
SELECT @numtitles=COUNT(*) FROM titles
RETURN @numtitles
My VB code is as below:
Dim cmd As New SqlCommand("ByRoyalty", Conxn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@numtitles", SqlDbType.Int)
.Parameters(0).Direction = ParameterDirection.ReturnValue
.Parameters.AddWithValue("@percentage", 100)
.Parameters(1).Direction = ParameterDirection.Input
.Parameters.Add("@avgprice", SqlDbType.Float)
.Parameters(2).Direction = ParameterDirection.Output
End With
Dim dr As SqlDataReader = cmd.ExecuteReader()
Running the above vb code reports the following error:
"Procedure or function ByRoyalty has too many arguments specified."
Please note that there are 2 parameters in the declaration, whereas third argument is declared inside the SP as;
DECLARE @numtitles Int
Even if we remove this statement and put this argument along with the other two in the declaration, I receive the same error.Please help