>>>>Hi,
>>>>
>>>>When adding a new record/row to a table (using CursorAdapter with SQL Server) I have noticed that the cursor does not automatically get the value of the newly created PK. So the PK field value in the cursor is out-of-sync with the table. What is the common practice in this case? Reload the values from the table (that is, calling Fill method of the CA)? or is there a better or more accepted practice?
>>>>
>>>>TIA.
>>>
>>>
>>>:-)
>>>I assume that your PK is integer IDENTITY column?
>>>Am I right?
>>
>>Yes, exactly.
>
>
>OK,
>As Naomi already said, use
>InsertCmdRefreshCmd and InsertCmdRefreshFieldList properties of CA
>And if you want to see how to use SCOPE_IDENTITY() instead of @@IDENTITY check Message #
1111814Boris, my understanding (from some reading on-line) is that SCOPE_IDENTITY() is better than @@IDENTITY. So I am looking at the message you suggested that describes how to get SCOPE_IDENTITY(). And I am trying to understand the code Alekesy wrote. One thing I don't understand and maybe you can help me. In his code:
cInsertCmd = cInsertCmd + "; DECLARE @id int; SELECT @id = SCOPE_IDENTITY()" + ;
"; EXEC #Get_ValHelper @id, ?@" + ;
this.Alias + "." + ALLTRIM(this.IDENTITY_Field)
what is the purpose of EXEC #Get_ValHelper @Id? and "?@" ? Are these necessary?
TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham