星期二, 6月 25, 2019

[VFP] CursorAdapter 使用 Store Procedure - 回傳 identity

該篇為 [VFP] CursorAdapter 使用 Store Procedure 的延續利用 identity 當成 PK,insert 時都有取回 identity 值的需求,筆記一下
CREATE PROCEDURE [dbo].[dmlEmployee_Insert]
(
  @UserName char(10) ,
  @HireDate datetime ,
  @Age int ,
  @UserID int output
)
AS
BEGIN

  SET NOCOUNT ON;

  INSERT INTO Employee (UserName , HireDate , Age)
   VALUES(@UserName , @HireDate , @Age)

  SET @UserID = SCOPE_IDENTITY()
END
GO
Insert Command 內宣告參數 (@lcUserID、名稱可以自訂) 來接就行

[VFP] CursorAdapter 使用 Store Procedure-2

在 VFP 中顯示 identity 值
lcUserID = ""
lbResult = TABLEUPDATE(1,.T.,"Employee")
IF lbResult = .F.
  AERROR(laError)
  MESSAGEBOX(laError(2))
ELSE 
  MESSAGEBOX(lcUserID)
ENDIF 

沒有留言:

張貼留言