StrataFrame Forum

Retrieving the new primary key after executing .NewRow and .Save

http://forum.strataframe.net/Topic23813.aspx

By Jeff Pagley - 7/10/2009

I could not find the answer on the forum or in the SF Help.  How do I retrieve the newly created primary key after executing the following code:

  Using job As New PRJTJobsBO
   With job
    .NewRow()
    .job_Customer = "jeff"
    .job_Name = "Jeff's Job"
    If .Save = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then
     Return ...newly created primary key??????
    End If
   End With
  End Using


Thanks,

Jeff

By Greg McGuffey - 7/10/2009

Assuming that the PK is auto incremented, you just access its property:



Using job As New PRJTJobsBO

  With job

    .NewRow()

    .job_Customer = "jeff"

    .job_Name = "Jeff's Job"

    If .Save = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

      Return .job_ID '-- if job_ID is the BO property that contains the ID

    End If

  End With

End Using
By Jeff Pagley - 7/13/2009

That was it.  I thought about that, but for some reason I was thinking when the BO added a record it reset the cursor to the first record in the BO and I needed to do something special to retrieve the new ID.

Thank You,

Jeff

By Greg McGuffey - 7/13/2009

Things are often as easy as they seem with SF. When I don't know how to do something, I'll often just try what might work and it often does. Glad that helped.
By Trent L. Taylor - 7/14/2009

Thanks, Greg! Smile