Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends, I want to use the OUTPUT key word in stored procedure to return value
to a front end control and is not working. Below are the codes.

STORED PROCEDURE Code
SQL
CREATE procedure prcSumSales
(
      @SubTotal Money OUTPUT
)
As
    Declare @salDate Datetime
    BEGIN
        Set @SubTotal = (Select Sum(SubTotal) From  dbo.DAILY_SALES
        Where SalesDate = @salDate)
        select @SubTotal
    END


VB Codes
Dim prmt(1) As OleDbParameter

Try
With cmd

con.ConnectionString = renConString
con.Open()
.Connection = net_55
.CommandText = "prcSumSales"
.CommandType = CommandType.StoredProcedure

prmt(0) = New OleDb.OleDbParameter("SalesDate", OleDb.OleDbType.VarChar, Integer.MaxValue)
prmt(1) = New OleDb.OleDbParameter("SubTotal", OleDb.OleDbType.Double, Integer.MaxValue)

prmt(0).Direction = ParameterDirection.Input
prmt(1).Direction = ParameterDirection.Output

.Parameters.AddWithValue("@salDate", txtEnterDate.Text.Trim)
.Parameters.AddWithValue("@SubTotal", 0)

Dim result As Double

.ExecuteNonQuery()
lblTotalSales.Visible = True

result = cmd.Parameters("@SubTotal").Value

lblTotalSales.Text = result
End With

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
Please this is the error message I get
Procedure or function prcSumSales has too many arguments specified.
Thanks.
Posted

1 solution

Hi there is nothing wrong in your code but your storedprocedure has not specified two parameter.

Your procedure should be like following.

SQL
CREATE procedure prcSumSales
(
      @SalesDate datetime,
      @SubTotal Money OUTPUT
)
As
    Declare @salDate Datetime
    BEGIN
        Set @SubTotal = (Select Sum(SubTotal) From  dbo.DAILY_SALES
        Where SalesDate = @salDate)
        select @SubTotal
    END
 
Share this answer
 
Comments
NanaKwame 11-Dec-13 7:20am    
hi Bhavesh Kashikar, thanks for your help anyway. It return zero (0) to the front end control.
BK 4 code 12-Dec-13 2:31am    
try this SP code

CREATE procedure prcSumSales
(
@SalesDate datetime,
@SubTotal Money OUTPUT
)
As
Declare @salDate Datetime
BEGIN
select @SubTotal= Sum(SubTotal) From dbo.DAILY_SALES
Where SalesDate = @salDate

END
NanaKwame 12-Dec-13 2:57am    
thanks for your effort. It still return null. I even execute at the query analyzer like this
exec prcSumSales '05-Nov-2013',0 and it still return the null value.
NanaKwame 12-Dec-13 9:29am    
After removing the this Declare @salDate Datetime line from the code every thing is okay now
with procedure.

CREATE procedure prcSum_DSales
(
@SalesDate datetime,
@SubTotal Money OUTPUT
)
As
BEGIN
Set @SubTotal = (Select Sum(SubTotal)
From dbo.DAILY_SALES
Where SalesDate = @SalesDate )
select @SubTotal

END

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