Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Finding id of inserted record in formview bound to LLBLGenProDataSource
 

Pages: 1
LLBLGen Pro Runtime Framework
Finding id of inserted record in formview bound to LLBLGenProDataSource
Page:1/1 

  Print all messages in this thread  
Poster Message
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
83 posts
# Posted on: 09-Apr-2008 09:39:54.  
I have a formview bound to an LLBLGenProDataSource. This LLBLGenProDataSource is attached to an oracle table whose primary key is filled from a sequence. How can I get at the PK of the record that has just been inserted?

I've looked into

Code:
Private Sub fvProjects_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles fvProjects.ItemInserted

    Debug.Print(e.Values("ProjectId"))

End Sub

But this just returns "". I can read the .Values for all fields other than the PK.

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14639 posts
# Posted on: 09-Apr-2008 10:25:17.  
Please check the following thread:
http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10250


  Top
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
83 posts
# Posted on: 09-Apr-2008 14:51:03.  
Thanks for your quick reply. I understand the concept of setting IsIdentity and have done this - the llblgen generated code is grabbing the next value for the primary key from the oracle sequence and using it when the new record is created.

I use a trigger like this so that llblgen can set the pk, but if I want to load records from oracle directly I can do so:

Code:

CREATE OR REPLACE TRIGGER PRR.PROJECT_PK_TIB
BEFORE INSERT
ON PRR.PROJECT REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
--Assign PK
IF (:new.project_id IS NULL) THEN
SELECT seq_project.NEXTVAL INTO
:NEW.project_id FROM DUAL;
END IF;

END;
/


However, what I need to do is to get the primary key for the "just inserted" record, so that I can redirect away from the form to show the "just inserted" record.

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14639 posts
# Posted on: 09-Apr-2008 15:25:06.  
If I understand you correctly, the the answer is the following:

In the mentioned thread, Frans wrote:
If you have to use the trigger, please add this line to the appSettings of the config file of your app:
<add key="OracleTriggerSequences" value="true"/>

(this is also documented in 'application configuration through config files' in the documentation )


  Top
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
83 posts
# Posted on: 10-Apr-2008 08:49:27.  
I don't think I have explained my question very well. To clarify: I have a asp.net formview (in insert mode) which I use to create a new entry in my oracle table and it works.


I would now like to find out the primary key of the newly created record as it is inserted so that I can redirect to another asp.net page showing as summary of the record that has just been added.
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14639 posts
# Posted on: 10-Apr-2008 11:27:45.  
Alright then please handle the LLBLGenProDataSource EntityInserted event, which is raised when LivePersistence is set to true and an entity was inserted successfully. The inserted entity is part of the event args.

  Top
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
83 posts
# Posted on: 14-Apr-2008 16:00:00.  
Spot on. Exactly what I wanted. Many thanks. For other's reference here is the code I ended up with...

Code:
Private Sub dsProjects_EntityInserted(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.DataSourceActionEventArgs) Handles dsProjects.EntityInserted

    ' Show the newly entered project.
    Dim newProject As ProjectEntity = e.InvolvedEntity
    Response.Redirect(String.Format("Proj.aspx?ProjectId={0}", newProject.ProjectId))

End Sub


It took me a while to find as it is a new feature added in v2.5 and I was still using v2.0. It was just the prompt I needed to upgrade, and the upgrade went seamlessly. Thanks again Walaa
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.