VB.Net project. I have the following stored procedure in SQL. It works fine but I am executing it with
Should I beusing something besides ExecuteNonQuery()? I want to return the next invoice number, but I also want to check the error code to confirm the update worked.
Auguy
Sylvania/Toledo Ohio
Code:
' Run Stored Procedure
...
myCommand.ExecuteNonQuery()
myErrorVal = CInt(myCommand.Parameters("@myError").Value)
NextInvoiceNbr = CInt(myCommand.Parameters("@NextInvoiceNbr").Value)
Code:
ALTER PROCEDURE [dbo].[Usp_CompanyInvoiceNumber_Select_And_Update]
@CompanyMasterFK int
,@NextInvoiceNbr int output
,@MyError int output
AS
BEGIN
SET NOCOUNT ON;
SELECT @NextInvoiceNbr = (SELECT NextInvoiceNbr From dbo.CompanyInvoiceNumber Where CompanyMasterFK = @CompanyMasterFK)
SELECT @MyError = @@ERROR
IF @MyError = 0
BEGIN
UPDATE dbo.CompanyInvoiceNumber
Set NextInvoiceNbr = NextInvoiceNbr + 1
,EditCount = EditCount + 1
WHERE CompanyMasterFK = @CompanyMasterFK AND NextInvoiceNbr = @NextInvoiceNbr
SELECT @MyError = @@ERROR
END
END
Auguy
Sylvania/Toledo Ohio