Ailton I use enough these two options that sql server gives us:
IDENT_CURRRENT returns the last identity value generated for a specific table in any session and scope.
But you need to ensure that your Insert worked, otherwise it will get the last Identity of the table even without inserting anything.
Ex:
SELECT IDENT_CURRENT('NOME_TABELA')
GO
SCOPE_IDENTITY returns the last Identity value generated for any table in the current session and scope.
This of course you should also ensure the INSERT worked, the difference is that instead of looking directly at the table it looks at the current session it was executed, IE, it will only get the Identity generated in that session.
Ex:
SELECT SCOPE_IDENTITY()
GO
The result of both options you can store in a variable and manipulate the way you want.
Your difficulty is getting the return value of the field identity or make the Datasnap function return its value?
– Victor T.