I have a stored procedure to copy a purchase order and all the order items associated with it but I need to know the new number when it's done. I found a sample on the web and modified it so that it looks like this
Then I call it from my application like this:
The PO gets copied, but NewID is 0. If I run the stored procedure from Query Analyzer, I get NULL.
I can't quite figure it out because @autonum is getting set correctly, otherwise my line items wouldn't have the correct number and they do. I've never worked with output parameters before so maybe I'm doing something wrong.
-Coco
![[auto] [auto] [auto]](/data/assets/smilies/auto.gif)
Code:
CREATE Procedure TestCopy
@ID int
, @autonum int OUTPUT
AS
begin tran
insert tblPO (OrderID, CompanyID, VendorID,
OrderedBy,InputAmount, Shipto, ShipVia,
Terms, FOB, TaxID, ContactName, Phone,
Fax, POComments)
Select OrderID, CompanyID, VendorID, OrderedBy,
InputAmount, Shipto, ShipVia, Terms,
FOB, TaxID, ContactName, Phone, Fax,
POComments
from tblPO where POID = @ID
set @autonum = @@identity
Insert tblPOItems (POID, ItemName, ItemQty, ItemDescrip,
ItemPrice)
select @autonum, ItemName, ItemQty, ItemDescrip,
ItemPrice
from tblPOItems where POID = @ID
commit tran
Code:
Public Function copyPO(ByVal OldID As Long) As Long
Dim NewID As Long
Dim conn As New ADODB.Connection
conn.Open
conn.testcopy OldID, NewID
conn.Close
copyPO = NewID
End Function
I can't quite figure it out because @autonum is getting set correctly, otherwise my line items wouldn't have the correct number and they do. I've never worked with output parameters before so maybe I'm doing something wrong.
-Coco
![[auto] [auto] [auto]](/data/assets/smilies/auto.gif)